iText: Do margins apply when using PdfContentByte? - itext

I created a new document with 36 points margin all around:
Rectangle rect = new Rectangle(1224f, 792f);
Document doc = new Document(rect, 36f, 36f, 36f, 36f);
I drew a rectangle at (0, 0) using PdfContentByte:
cb.rectangle(0, 0, 100, 100);
cb.fill();
The rectangle gets drawn at the lower-left hand corner of the page. It ignores the margins completely. Is this the expected result?

Is this the expected result?
Yes, it is. The margins only are taken into account by operations adding content via the Document.
Whenever you access the content directly (DirectContent, UnderContent,OverContent), you can draw wherever you want.
When creating footers or headers, you actually rely on that behavior.
Furthermore, the margins have no influence on the coordinate system. As the coordinate system is configurable, one could have chosen 0,0 to be the lower left of the margin border. Actually you can do so by defining a page size rectangle that way. But that is not the normal usage of iText.

Related

Reduce Fill Image from Two Sides

I have set Image Type to Filled because I want to reduce the size of my filling area.
On the left side, you can see my progress bar within the attached image.
Within the inspector, you can clearly see I have set Fill Origin from Top so image size gets reduced from the bottom.
Now one twist I want, I want to reduce an image from both sides top and bottom, I have already played with Image component different values but I can't able to get success.
Overall I want to reduce the size of the image from the top and bottom.
There are 2 ways you can achieve this effect:
You can instead change the Y scale of the image, whilst the Y pivot is 0.5 this will make it shrink from top to bottom, but this will only work if the sprite looks the same even if shrunk down.
If your sprite's shape won't allow for changing the scale like that, you could also split it into 2 sprites at the midpoint and put them next to each other, and then have the top side fill from bottom, and the bottom side fill from top.

Map Center & Bounds do not update when Container Div is Resized

(pretty new to Mapbox and JS, so I'm in a bit over my head)
I'm working on a page where the user needs to adjust the size of map container. It needs to be able to get accurate bounds and center point of the resized map (via map.getBounds and map.getCenter).
When I use JS to adjust the size of the container div, the center and bounds are not adjusted.
Fiddle: http://jsfiddle.net/xcow63sm/3/
Panning/zooming results in updated center and bounds. Browser window resize (if you have width or height set to 100%) works too. I would expect changing the container dimensions would adjust center and bounds.
However, if you use the form fields to adjust the height/width of the container div, the center and bounds do not. I've tried (with increasing desperation):
function resize (){
var inputwidth = document.getElementsByName("mapwidth")[0].value;
var inputheight = document.getElementsByName("mapheight")[0].value;
var mapDiv = document.getElementById('map');
var mapcenter = map.getCenter();
mapDiv.style.width = inputwidth;
mapDiv.style.height = inputheight;
map.updateSize();
map.update();
map.resize();
map.invalidateSize();
document.getElementById("mapcenter").value = mapcenter;
Edit: this seems to apply but I can't make sense of it: Resizing a leaflet map on container resize
If I understand you, you have two issues: you don't like how the map is positioned after its size changes, and you're getting white space.
Map positioning after resize
There are at least three valid options for how a map should update if, say, its width and height are suddenly doubled:
keep the same northern and western bound, extend the eastern and southern bounds. (Expanding the viewing area right and down)
move all four bounds outwards (keeping the centre of the map in the same place)
leave all four bounds where they are are, but change the zoom, so the same geographic area is displayed, but in more detail.
I think your issue is that Mapbox is choosing option 1, but you want one of the other two options. The solution, as I think you've discovered, is simply to do your own maths and set the bounds how you want them.
Map failing to repaint correctly
Your second issue is that when you resize, calling map.resize() isn't updating the internal size of the map properly, and you're left with white space. The reason for this is you're using animated CSS properties. So when you do this:
mapDiv.style.width = inputwidth;
mapDiv.style.height = inputheight;
map.resize();
This doesn't work because the map's size hasn't actually transitioned to the new size yet. You can work around it like this:
mapDiv.style.width = inputwidth;
mapDiv.style.height = inputheight;
window.setTimeout(()=>map.resize(), 500);
There's probably a better event you can listen to, to keep updating as the map area expands.
Updated fiddle here: http://jsfiddle.net/xcow63sm/11/
Btw you should consult the documentation here. I'm not sure where you got map.updateSize() from but that's not Mapbox-GL-JS :)

iTextSharp - Scaling and positioning page

I am reading an existing PDF file into a new PDF file, and scaling the first page based on the page dimensions. The page gets scaled to 90-95% in order to make room for some footer text. The problem I have is that the resulting scaled page leaves white space at the top of the page, NOT the bottom. Is there a way to control the results so that they start in the top left of the page and not the bottom left?
Here's my code that adds the scaled page:
cb.AddTemplate(importedPage, scaleSize, 0, 0, scaleSize, 5, 20);
Object "cb" is a PDFContentByte class, while "scaleSize" is a float set to .9 or .95. The scaling works great, but the positioning is an issue. Thanks!
figured it out: the value of "20" for the final parameter was incorrect. A value of 100 is far more suitable for my purposes, and now I understand far better the coordinate system in PDF/iText. For those interested, the 0, 0 point for a PDF document is the lower left corner.

Matlab - change height of the text field on the whole figure

Is there a way to change the height of a text field on the whole figure without changing the x and y position?
To change we must use the position, which requires to change the coordinates. I would like to change only the height, without changing x and y.
Just store the current x and y, and use those in your set call like so:
old_pos = get(text_field_handle,'Position');
set(text_field_handle,'Position',[old_pos(1:2),new_width,new_height]);
Well, you can change the FontSize property, this won't change the coordinates, but will increase width as well as height. See Text Properties in the doc for more details.
I am assuming you are working with uicontrol('style','text').
From the uicontrol properties you have:
Position
position rectangle
*Size and location of uicontrol*. The rectangle defined by this property
specifies the size and location of the control within the parent figure
window, uipanel, or uibuttongroup. Specify Position as:
[left bottom width height]
where left and bottom define the distance from the lower-left corner of the
container to the lower-left corner of the rectangle. width and height are the
dimensions of the uicontrol rectangle.
You can then just change the width and height keeping the original left and bottom.
One can set the Margin property of a text object to increase the height of the object without changing the fontsize, but this influences both the height and the width of the text object. I am not sure what it means to make the height smaller than what Matlab thinks is the text height, so I will assume you are interested in increasing the size.
Increasing the height of the text object is relatively easy if you are willing to use the LaTeX interpreter. You just need to add an "empty" box of whatever height you want:
text(0.5, 0.25, 'Hello World\parbox{\textwidth}{\vspace{1in}}', 'Interpreter', 'LaTeX', 'BackgroundColor',[1, 0, 0]);
This won't increase the height by exactly 1 inch, instead it will be more like 1 inch minus a baseline skip. Determining the actual height increase in displayed units adds even more problems. You might be able to change the height with unicode characters, and hence skip the LaTeX interpreter, but I have no idea how.

StretchableImageWithLeftCapWidth stretching wrong portions

I am trying to use a UIImage with stretchableImageWithLeftCapWidth to set the image in my UIImageView but am encountering a strange scaling bug. Basically picture my image as an oval that is 31 pixels wide. The left and right 15 pixels are the caps and the middle single pixel is the scaled portion.
This works fine if I set the left cap to 15. However, if I set it to, say, 4. I would expect to get a 'center' portion that is a bit curved as it spans the center while the ends are a little pinched.
What I get is the left cap seemingly correct, followed by a long middle portion that is as if I scaled the single pixel at pixel 5, then a portion at the right of the image where it expands and closes over a width about twice the width of the original image. The resulting image is like a thermometer bulb.
Has anyone seen odd behavior like this and might know what's going on?
Your observation is correct, Joey. StretchableImageWithLeftCapWidth does NOT expand the whole center of the image as you would expect. It only expands the pixel column just right of the left cap and the pixel row just below the top cap!
Use UIView's contentStretch property instead, and your problem will be solved. Another advantage to this is that contentStretch can also shrink a graphic properly, whereas stretchableImageWithLeftCapWidth only works when making the graphic larger.
Not sure if I got you right, but LeftCapWidth etc is made for rounded corners, with everything in the rectangle within the rounding radius is stretched to fit the space between the 'caps' on the destination button or such.
So if your oval is taller or wider than 4 x 2 = 8, whatever is in the middle rectangle will be stretched. And yours is, so it would at least look at bit ugly! But if it's not even symmetrical, something has affected the stretch. Maybe something to do with origin or frame, or when it's set, or maybe it's set twice, or you have two different stretched images on top of each other giving the thermometer look.
I once created two identical buttons in the same place, using the same retained object - of course throwing away the previous button. Then I wondered why the heck the button didn't disappear when I set alpha to 0... But it did, it's just that there was a 'dead' identical button beneath it :)