I know that iText PDF supports painting paragraphs which is quite good. However, I was wondering whether (besides using tables) is it possible to do custom drawing of the background of paragraphs, like adding a rounded border box etc.?
I know that there's the VerticalPositionMark interface that allows one to paint on the current y position, however for a paragraph I'd need to know his exact positions to be able to paint into the background first (including any margin from the paragraph etc.).
Is there any way besides using tables for every single box?
thanks!
Alex
Related
I want to draw Strings in my Libgdx game but i cant use BitMap Fonts because the scale of my game is to smal to use them.
It sounds like you mean the scale of your viewport is too small to show fonts correctly. There are two solutions. The first is better for legibility while the second is quick and dirty.
One is to use a second viewport for the UI that has an appropriate scale for text. You would first call gameViewport.apply(), draw the game, and end the batch. Then use uiViewport.apply() and then draw the UI. The downside with this method would be if you want to draw text that aligns with moving objects in the game, you would have to use the two viewports to convert coordinates. Otherwise, this is the ideal method to get a crisp looking UI. Ideally you would use a ScreenViewport and select a font size at runtime based on the screen dimensions, either by shipping your game with multiple versions of the font at different scales, or by using FreeTypeFontGenerator.
The second method is to scale down all your text. First call bitmapFont.setUseIntegerPositions(false) do it won't round off positions to integers. Then call bitmapFont.setScale() with however much you want to shrink it to fit in your game viewport.
There is a gdx-freetype project:
https://www.badlogicgames.com/wordpress/?p=2300
and it uses TrueType fonts as source to generate bitmap font on the fly.
Not sure how stable this is - didn't use it.
Both methods are not documented both and does not seem to behave as I would expect.
mylabel.setFontScale(3f); makes the apparent text 3 times larger (what I'm looking for) but does not center properly when using it with Align.center.
mylabel.setScale(3f); does nothing as far as I could see.
What is the difference between those 2 methods and what one should I use to make my label bigger and properly centered ?
setFontScale() indeed enlarges the font, this is often unwanted since scaling up pixelizes the font.
label.setScale() does work if you are not using a layout actor like a table. When actors go inside a layout then the layout is responsible for setting the sizes and position. For example, you have control over this once you put it inside a table cell.
table.add(myLabel).width(300).height(80).padLeft(100).expandX();
Detailed documentation on working with a table.
This however just sizes the label, not the text inside. You can still do setFontScale(3f) but this will pixelate the font. You have 2 better options:
create a extra bitmap font in Hiero 3 times larger.
Use Gdx.Freetype to import a .ttf and generate fonts on run-time.
I am generating a pdf using java and doing the formatting with XSL ..I have few tables that are being generated in the pdf . Problem is the border of the tables are not of even darkness . somepart of the line is dark and some part is light .
How can I correct this formatting .
Thanks
Sometimes a table border might look lighter depending on your Zoom level. If you zoom in and the borders are displaying weird it must be your code to display borders.
Check all of your border settings for:
table
header row
body row
footer row
All of these can be set with different border-top, border-bottom, border-left, and border-right thicknesses.
Print the document. If they are all the same then it is the viewer and resolution of the monitor that is the issue. Many FO renderers use polygons to represent borders so that corners are mitered as they should be for different colors or sizes. Some PDF viewers (especially Reader on Windows) cannot handle thin polygons when the screen representation is but one or two pixels.
Likely there is nothing wrong with the file, it is only the view application.
Best way to set the table properties like color ,font ,alignment is to set those in the <xsl:attribute-set> and then later call this using <use-attribute-sets>.This way you would not have to set the properties at every table cell ,just need to call the attribute set .
I have a large component (say width=4000px, height=200px) and would like to be able to see it entirely even on a small screen.
I don't see any easy way to do a wrapping component, my idea is the following :
given a factor (for example 4), the component would be of size 1000x800, by wrapping the child to 4 lines. The size requests would be translated in reverse to reshape the child, and so on. On painting, the component would call the paint(Graphics) of the child 4 times with a correct Graphics argument that would map the wrapped space to the child's space.
However, I can't see how to handle all the events : should I set eventlisteners for every children-generated event (PropertyChange) and for every parent-generated event (Mouse, Key, Resize, ....) ? This seems quite a lot of mapping, and I'd be happy to ear of an easier way of doing that...
I haven't looked too much at the JViewport implementation, but maybe this could help me don't you think?
thanks for your suggestions!
Frederic.
Edited to answer some of the comments that suggest to redesign the component :
Allow me to disagree here : making a component is one job, showing it is another. If I want to show it with scroll bars, I use a Scroll-Pane, whereas if I want to show it split in 4 lines, I want to use a similar solution.
I am the designer of the component in question (and had sharp words with myself, as suggested, but it lead me nowhere :-) ). I actually added "line-wrapping code" in it but it appears (really quickly!) that adding point space conversion, painting management in the codes of the component itself makes it really really messy, which is the reason why I imagine that a specialized component is a really a better solution.
Furthermore, making a custom component lets me reuse it far more easily as a "wrapper" for any other component.
Imagine if you had to recreate a JScollPane-like functionality every-time you use a JScollPane, dealing with scroll position, buffered painting and everything inside your own components : hopefully you don't have to!
You're approaching this the wrong way. It's the contents of the component, not the component itself you should be thinking about. If you want it to be 1000x800, make it that size. If the component has content - e.g. text or other components - calculate their positions appropriately. (You probably won't be able to use the standard layouts, and may end up writing your own). You'll probablky need to recalculate the layout if the component's width changes.
Don't call paint 4 times. If you've calculated the layout of the component, it's children or text, correctly then paint should just work.
In response to the comment: wrapping a histogram, in the sense of inserting arbitrary line breaks, is not likely to be useful. With graphical components the 'breaker' won't know exactly where to insert the breaks; you will also lose any information attached to the Y axis. Much better solutions would be to simply shrink the histogram in the horizontal direction until it fits the screen width, or to draw four histograms one under the other, duplicating the Y axis information for each. Alternatively allow horizontal scrolling over the whole histogram; or change the axes so the histogram is drawn horizontally. If none of the above work, perhaps because you have many hundreds of histogram bars, maybe a more interactive approach where you amalgamate some of your histogram bars together to give an overview, and allow the user to 'drill down' into the plot to get at the more detailed information.
If the issue is that you can't modify the original component, and it draws a fixed size image, then your best bet may be to call 'paint(Graphics)' on it four times with appropriate transforms and clipRects on the Graphics to draw the four parts 'stacked'. But frankly you may be as well off throwing away the original component. Histograms are not that hard to draw, and there are plenty of free plotting packages to help you. And be very rude to the designer of the original component if you meet them.
You don't mention scrolling. Put it on it's own pane and then put that pane into a scrolling panel.
You know in MS Word, you can write text and draw&put shapes anywhere you want.. in the text when you hit enter and get to a new line, the shapes below your cursor also moves down one line? I want to implement that property in Java on a pane, using components as the shapes and text. How can I provide absolute positioning for shapes but at the same time preserve the space between them? I'll appreciate any idea, cause I'm almost out of ideas.
Maybe you could use SpringLayout?
Spring layouts do their job by defining directional relationships, or constraints, between the edges of components. For example, you might define that the left edge of one component is a fixed distance (5 pixels, say) from the right edge of another component.