unable to set background color on iTextSharp signature appearance - itext

Does anyone have any ideas on how to set the background color on the PdfSignatureAppearance rectangle in iTextSharp? I create the PdfSignatureAppearance object and can set its positioning on the page, but the rectangle only has a transparent background. I'm trying to apply a color (any really).
I've tried creating a new iTextSharp.text.Rectangle then setting the rect.BackgroundColor = new BaseColor(System.Drawing.Color.Yellow); That doesn't work. I saw someone else trying to something similar by applying the styles to the layer2 of the signature appearance object. I've tried these with no luck.
PdfTemplate sigAppLayer2 = appearance.GetLayer(2);
sigAppLayer2.SetRGBColorFill(255, 0, 0);
sigAppLayer2.SetGrayFill(2);
sigAppLayer2.BoundingBox.BackgroundColor = new BaseColor(System.Drawing.Color.Yellow);
Anytime I try one of the above styling changes to the layer2 the visible signature disappears on the PDF. If I try applying it to layer 0 or layer 1 then nothing happens. I'm assuming then I'm touching the correct layer (2).
Any ideas? The goal is to just get a background on the signature box vs having it be transparent.
See comment below. I tried this as well setting against layer 2 and layer 0. Both result in a red box, but the signature text is missing.
PdfTemplate sigAppLayer2 = appearance.GetLayer(2);
Rectangle rect = sigAppLayer2.BoundingBox;
PdfTemplate sigAppLayer0 = appearance.GetLayer(0);
sigAppLayer0.SetRGBColorFill(255, 0, 0);
sigAppLayer0.Rectangle(rect.Left, rect.Bottom, rect.Width, rect.Height);
sigAppLayer0.Fill();

You need to draw the rectangle and fill that rectangle with the fill color.
From memory (untested), you need something like this:
PdfTemplate sigAppLayer2 = appearance.GetLayer(2);
Rectangle rect = sigAppLayer2.BoundingBox;
sigAppLayer2.SetRGBColorFill(255, 0, 0);
sigAppLayer2.Rectangle(rect.Left, rect.Bottom, rect.Width, rect.Height);
sigAppLayer2.Fill();

This is the way:
PdfTemplate sigAppLayer2 = appearance.GetLayer(2);
Rectangle rect = sigAppLayer2.BoundingBox;
sigAppLayer2.SetRGBColorFill(255, 0, 0);
sigAppLayer2.Rectangle(rect.Left, rect.Bottom, rect.Width, rect.Height);
sigAppLayer2.Fill();
sigAppLayer2.ResetRGBColorFill();// <--------- you needs this
sigAppLayer2.BeginText() ...etc

Related

Is there any way to change FilterMode of custom Sprite in Unity?

I'm making 2D pixel graphic game and want to use custom Sprite using Texture2D class.
So I used code like this:
Sprite.Create(texture, new Rect(0, 0, size, size), new Vector2(0.5f, 0.5f), 32)
But this created sprite has FilterMode "Bilinear". I want to change it to "Point (no filter)".
Changing FilterMode in inspector is very easy but I don't know how to change it in runtime. Is there any way to solve this problem?
You can only change the filter mode of the texture.
texture.filterMode = FilterMode.Point;
Sprite.Create(texture, new Rect(0, 0, size, size), new Vector2(0.5f, 0.5f), 32);
you can do this but it doesnt really seem to work. Nor does setting the filter mode of the texture before Sprite.Create.
spriteRenderer.sprite.texture.filterMode = FilterMode.Point;

Javafx scale a control according to it's parent

I am writing a new Imageview with mask in Javafx.
The mask can show according to the direction of mouse.
Using Timeline makes it work well. But when the mask leaves, the mask is still visible.
I want to hide the part of mask, which is out of the Image. How can I scale it?
When mouse enter:
When mouse leave:
And my animation code
private void leftOut() {
KeyFrame k1 = new KeyFrame(Duration.ZERO, new KeyValue(mask.translateXProperty(), 0));
KeyFrame k2 = new KeyFrame(time, new KeyValue(mask.translateXProperty(), control.getWidth()*-1.0));
timeline = new Timeline();
timeline.getKeyFrames().addAll(k1,k2);
timeline.play();
}
Other directions are just like this.
You don't need to resize the mask at all. Simply apply a clip to it that has the same size as the image:
Image image = new Image("https://upload.wikimedia.org/wikipedia/commons/thumb/b/b1/Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF.jpg/164px-Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF.jpg");
ImageView imageView = new ImageView(image);
// init mask
Label mask = new Label("SomeText");
mask.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
mask.setPrefSize(image.getWidth(), image.getHeight());
mask.setStyle("-fx-background-color: rgba(255, 255, 255, 0.6);");
mask.setAlignment(Pos.CENTER);
// create clip
Rectangle clip = new Rectangle(image.getWidth(), image.getHeight());
mask.setClip(clip);
// keep clip in position horizontally in root
clip.translateXProperty().bind(mask.translateXProperty().negate());
StackPane root = new StackPane(imageView, mask);
root.setPrefSize(500, 500);
root.setStyle("-fx-background-color: orange;");
// probably a bit simpler to use TranslateTransition instead of Timeline
TranslateTransition transition = new TranslateTransition(Duration.seconds(5), mask);
transition.setByX(image.getWidth());
transition.play();

ios-charts Charts for Swift - purposely bleed/overflow chart bars

I'm using a Bar Chart that I'm trying to make look like a design. The design's bars overflow a bit at the bottom and have a transparency gradient on them. I can't find any property that you can use for this and I guess I'll have to override somewhere. I've also tried to draw layers on top of the graph at the bars positions/bounds without success.
I tried overriding the BarChartRenderer and change the Y-positions, but since the graph is supposed to be "scrollable" by default it clips the bar.
I've already disabled the scrolling/moving/zooming functions because I don't need them:
doubleTapToZoomEnabled = false
highlightPerDragEnabled = false
highlightPerTapEnabled = false
clipValuesToContentEnabled = false
You can set the minimum axis value so that it set the bottom line correct try this code as
barChartView.leftAxis.axisMinimum = __Your minimum bar value__ i.e. 17000 //that is mention in your above graph
Solved it by drawing my own layers over the bars and then remove the old bars because of their anti-aliasing. This way it will be easier to implement the gradient too, and it works because you won't be able to move/scale the chart.
let bottomY = self.contentRect.maxY - leftAxis.gridLineWidth
for (_, bar) in self.barData!.dataSets.enumerated() {
let layer = CALayer(),
barBounds = self.getBarBounds(entry: bar.entryForIndex(0)! as! BarChartDataEntry),
// 30 extra height at bottom
frame = CGRect(x: barBounds.minX, y: barBounds.minY, width: barBounds.width, height: (bottomY - barBounds.minY) + 30)
// Set the new frame size, Z position and background
layer.frame = frame
layer.zPosition = 10
layer.backgroundColor = bar.color(atIndex: 0).cgColor
// Add the new bar layer and remove old bar
self.layer.addSublayer(layer)
bar.clear()
}

iText - How to set stroke width and opacity for PdfAnnotationInk

What functions should I call to set the stroke width and opacity when drawing ink type annotation?
I have go through the class API for PdfAnnotation and PDFStamp, but it seems there are no functions to set the width and opacity directly. Any suggestions? Thanks.
My sample program:
final String sourceFile = "C:\\PdfAnnotation\\sample.pdf";
final String destFile = "C:\\PdfAnnotation\\output\\output.pdf";
PdfReader reader = new PdfReader(sourceFile);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(destFile));
Rectangle rect = new Rectangle(52.92f, 397.56f, 173.36f, 530.67f);
float[][] inkList = {{61.736111f,530.669250f,61.295139f,525.820984f,61.295139f,518.768860f,
61.295139f,505.986969f,61.295139f,490.560547f,61.295139f,470.726562f,59.972221f,452.214844f,
57.767361f,434.143890f,56.003471f,418.276703f,53.357639f,404.172516f,51.593750f,391.390625f,
50.711807f,382.134766f,49.829861f,376.845703f},
{68.350693f,453.537109f,73.201385f,453.977875f,79.375000f,453.977875f,85.107635f,453.977875f,92.163193f,453.977875f,
100.541664f,453.977875f,108.038193f,453.977875f,117.298615f,453.977875f},
{112.447914f,509.072266f,112.006943f,505.105469f,112.006943f,498.053375f,112.006943f,488.797516f,112.006943f,472.930328f,
112.006943f,457.503906f,112.006943f,441.636719f,112.006943f,426.210297f,111.565971f,412.106110f,
111.125000f,401.968750f,111.125000f,391.831390f},
{161.836807f,454.859375f,161.836807f,449.129547f,161.836807f,441.636719f,161.836807f,433.262360f,161.836807f,
423.125000f,161.836807f,412.546875f,161.836807f,405.054047f,161.836807f,398.442719f,161.836807f,392.712891f,
161.836807f,389.627594f},
{163.159729f,485.712250f,170.215271f,469.845062f}
};
PdfAnnotation an = PdfAnnotation.createInk(stamper.getWriter(), rect, "", inkList);
an.setColor(new BaseColor(30, 89, 255));
an.setFlags(PdfAnnotation.FLAGS_PRINT);
stamper.addAnnotation(an, 1);
stamper.close();
reader.close();
What functions should I call to set the stroke width and opacity when drawing ink type annotation?
There are two answers:
If the PDF viewer creates the appearance
The PDF specification mentions
BS dictionary (Optional) A border style dictionary (see Table 166) specifying the line
width and dash pattern that shall be used in drawing the paths.
as another entry specific to the Ink annotation dictionary. This at least allows you to set the stroke width but not the opacity. Simply add a line like this
PdfAnnotation an = PdfAnnotation.createInk(stamper.getWriter(), rect, "", inkList);
an.setColor(new BaseColor(30, 89, 255));
an.setFlags(PdfAnnotation.FLAGS_PRINT);
// vvv set line width to 5:
an.setBorderStyle(new PdfBorderDictionary(5, PdfBorderDictionary.STYLE_SOLID));
// ^^^ set line width to 5:
stamper.addAnnotation(an, 1);
to set the stroke width to 5 and get a result like this:
If the PDF supplies the appearance
The PDF specification also mentions
The annotation dictionary’s AP entry, if present, shall take precedence
over the InkList and BS entries; see Table 168 and 12.5.5, “Appearance
Streams.”
Thus, you can create a PdfAppearance, use its methods to create an appearance exactly as you want it, including transparency, and set it as the normal appearance of the annotation. PDF viewers then shall display the annotation just like you want.

Raphael-GWT: fill image of a shape (Rect) appears offset. How to resolve this?

I'm wondering about the behavior of {Shape}.attr("fill","url({image.path})").
when applying a fill image to a shape:
public class AppMapCanvas extends Raphael {
public AppMapCanvas(int width, int height) {
super(width, height);
this.hCenter = width / 2;
this.vCenter = height / 2;
...
Rect rect = this.new Rect(hCenter, vCenter, 144, 40, 4);
rect.attr("fill", "url('../images/app-module-1-bg.png')"); // <--
...
}
}
The background image seem to teal accross the canvas behind the shape, thus gets weird positioning (an illustration snapshot is enclosed - i marked the original image borders in red).
This seem to resolve itself in the presence of an animation along a path (a mere path.M(0,0) is sufficiant).
How can i position the fill-image properly in the first place?
The proper way to do this from what I can understand would be to use an SVG pattern declaration to specify the portion and position of the image you would want to use. Then you would use that pattern to fill the rectangle element. Unfortunately, the Raphael javascript library doesn't have support for patterns... so there's no direct way to use an image to fill a rectangle.