Shape of a sub-string of caracters
I need to get the shape of a sub-string of caracter from one I render.
There is what a want to achieve, redering a text with a border 2 everywhere but on two caracter in the middle where the border would be 10.
I can't just crop the textlayout shape because the border will then be discontinued.
I tried using Area and merging Shapes obtained through getCaretShape with some TextHitInfo.leading(x), but those Shape are just empy (x,y, but 0 width, 0 height) : /
Is there a way to use TextHitInfo + getCaretShape to obtain the Shape of a caret and now just a positionned empty Shape?
Thx.
Are you starting off with a string or a shape.If you have a string, can you create a shape of the first substring, then a shape of the two characters, then a third shape. The positioning obtained from the FontMetrics methods.Or did I not understand the question properly ?
You did understand properly.But, since because the preceding and following letter can change the shape of some letters, I thrust a shape just made of the substring (whith 0 link implied) could not match the shape that substring has in the whole string's shape.
Does the whole string (as a shape) need to be drawn
If you have the string "abcDEfg", do you need to draw the whole string ?
Draw "abc" then "DE" with a different border, then "fg"
If you used FontMetrics, it could be drawn to overlay (exactly) the shape of the whole string, then you could just draw the "DE" over the top with a different border. The border would of course overlap the surrounding characters.
Quote for FontMetrics JDoc : "[...] Also, in some scripts, certain character sequences can be represented by a single shape, called a ligature. Measuring characters individually does not account for these transformations."Could you please explain to me how to proceed please?
This is a reference to 'unussual' letter formation and not to (for example) the Latin characters in common use in English.
This section may refer to some cursive/handwriting-imitating scripts where the advance is dependant on the letter before/after creating an overlap.
Also it seems to include things (of which I have never used) such as the 'ae' character used in French.
Unless your application has to be incredibly robust or internationalized, I would not worry too much.
Bamkin
How do you position caracters usings FontMetrics? O_oCan you please show me a sample of code that will draw a full line of text, character one-by-one?Message was edited by: Sergejava
It would be looking something along the lines of ...
String oneLetter=aString.substring(1, 2);//this all works with strings, you so not have to draw one letter at a time.
Font font=new Font("Ariel", Font.PLAIN, 30);//set the font
FontMetrics fm=getFontMetrics(font);get the fontmetrics of this font
int letterWidth=fm.stringWidth(oneLetter);//this is the width that the shape will be, when drawn with an outline 1px wide.
//you must programme extra gap when drawing with thick lines, not difficult
TextLayout tl=new TextLayout(oneLetter, font, g.getFontRenderContext());
Shape letter=tl.getOutline(null);//this is the Shape to be drawn onto Graphics2D
I copied these lines from an old programme... Hope I didn't miss anything out.
Let me know how it works for you
Bamkin.
That doesn't solve positionning issue.
The
int letterWidth
is the width of this shape therefore
letterWidth+(outlineWidth*2)=width of this shape as drawn
Position the next character letterWidth to the right
graphics.draw(letter);
graphics.translate(letterWidth, 0);
//draw next letter, ect