cheungj
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2013
05:39 PM
Issues with roFont.getOneLineWidth
Has anyone encountered an issue with roFont.getOneLineWidth(string, max size) not returning the right width for a particular string for specific fonts
essentially what I have is an image canvas with a layer that has a piece of text that is only suppose to be on one line. the font is set but the fontsize is dynamic.
so for a particular font size say 50 what happens is when i use the roFont.getOneLineWidth it returns a rectangle width which is smaller then it is to fit the text on one line so it word wraps. has anyone encountered an issue like this with that method before?
essentially what I have is an image canvas with a layer that has a piece of text that is only suppose to be on one line. the font is set but the fontsize is dynamic.
so for a particular font size say 50 what happens is when i use the roFont.getOneLineWidth it returns a rectangle width which is smaller then it is to fit the text on one line so it word wraps. has anyone encountered an issue like this with that method before?
15 REPLIES 15
destruk
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2013
05:49 PM
Re: Issues with roFont.getOneLineWidth
Yes, if the area you are writing your text to is too narrow to fit on one line, it wraps the text to fit, so if you check the height value as well you can get the actual size/area it is using. You can avoid the issue by using a fixed-width font instead of proportional, and using a set font size instead of a variable font size selection, and that way you could simply count the number of standard characters you have in the line rather than checking width and individual character metrics.

RokuMarkn
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2013
08:55 AM
Re: Issues with roFont.getOneLineWidth
Destruk, I don't think that's the case. ifFont.GetOneLineHeight takes no parameters so it can't return the height of a specific wrapped string. GetOneLineWidth also doesn't take any wrapping into account. I'm not aware of any cases where GetOneLineWidth would return less than the space required to draw the string as one line, unless it's larger than the MaxWidth parameter. Can you provide an example?
--Mark
--Mark
destruk
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2013
09:29 AM
Re: Issues with roFont.getOneLineWidth
I was using .Size.W and .Side.H for that.
Maybe getonelinewidth and getonelineheight is handled differently.
Maybe getonelinewidth and getonelineheight is handled differently.
cheungj
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2013
09:41 AM
Re: Issues with roFont.getOneLineWidth
Certainly I have example right here
fontsize is dynamic integer
Stringvalue = "Hello foo foo enjoy"
font = m.fonts.GetFont("BPreplay",fontSize,true,false)
txtRect.w = font.GetOneLineWidth(stringvalue, canvas.w*2)
so when i print out the txtRect.w its smaller then what the text requires to fit on oneline. Should I provide an offset so it has additional padding or space?
fontsize is dynamic integer
Stringvalue = "Hello foo foo enjoy"
font = m.fonts.GetFont("BPreplay",fontSize,true,false)
txtRect.w = font.GetOneLineWidth(stringvalue, canvas.w*2)
so when i print out the txtRect.w its smaller then what the text requires to fit on oneline. Should I provide an offset so it has additional padding or space?

RokuMarkn
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2013
10:16 AM
Re: Issues with roFont.getOneLineWidth
Ok, I tried these commands in the debugger:
This drew the text and then drew a yellow rectangle that exactly matches the width of the text, so it seems to be working here. Can you reproduce your problem with the default font? If not, perhaps there is a problem with your font file. If you can reproduce with the default font, please post the complete source.
--Mark
BrightScript Debugger> reg = CreateObject("roFontRegistry")
BrightScript Debugger> font = reg.GetDefaultFont()
BrightScript Debugger> s = "Hello foo foo enjoy"
BrightScript Debugger> w = font.GetOneLineWidth(s, 10000)
BrightScript Debugger> ?w
336
BrightScript Debugger> screen = CreateObject("roscreen")
BrightScript Debugger> screen.DrawText(s, 100,100,&hffffffff,font)
BrightScript Debugger> screen.DrawRect(100,140,336,32, &hffff00ff)
BrightScript Debugger> screen.Finish()
This drew the text and then drew a yellow rectangle that exactly matches the width of the text, so it seems to be working here. Can you reproduce your problem with the default font? If not, perhaps there is a problem with your font file. If you can reproduce with the default font, please post the complete source.
--Mark
greubel
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2013
11:11 AM
Re: Issues with roFont.getOneLineWidth
I've been having a lot of problems trying to get text to fit with roImageCanvas.
I coded this up for roImageCanvas not roScreen, which is what cheungj asked about.
It appears the Default font on HD is "Large" but not on SD displays. I even tried "Huge" but it still didn't fill the rectangle.
"GetOneLineWidth" looks close for HD BUT no where near on SD displays.
Results SD

Results HD
I coded this up for roImageCanvas not roScreen, which is what cheungj asked about.
It appears the Default font on HD is "Large" but not on SD displays. I even tried "Huge" but it still didn't fill the rectangle.
"GetOneLineWidth" looks close for HD BUT no where near on SD displays.
reg = CreateObject("roFontRegistry")
scr = CreateObject("roImageCanvas")
port = CreateObject( "roMessagePort" )
scr.SetMessagePort( port )
scr.SetLayer( 0, { color: "#FF808080" } )
scr.Show()
s = "Hello foo foo enjoy"
font = reg.GetDefaultFont()
w = font.GetOneLineWidth( s, 10000 )
h = font.GetOneLineHeight()
size = "Large"
txt = "w = "+w.ToStr()+" h = "+h.ToStr()+" "+size
items = CreateObject( "roArray", 100, 1 )
items.Push( { color: "#FFFFFFFF", TargetRect:{x:100,y:100,w:w,h:h}} )
items.Push( { Text:s,
TextAttrs:{ Color:"#FFFF0000", Font:size, HAlign:"Left", VAlign:"Middle" },
TargetRect:{ x:100,y:100,w:w,h:h }} )
items.Push( { Text:txt,
TextAttrs:{ Color:"#FF000000", Font:"Large", HAlign:"Left", VAlign:"Middle" },
TargetRect:{ x:100,y:50,w:600,h:60 }} )
scr.SetLayer( 1, items )
Results SD

Results HD

greubel
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2013
12:32 PM
Re: Issues with roFont.getOneLineWidth
It appears there are more problems with "getOneLineWidth".
It does not take into account the font face, bold or italic, which causes text wrapping.
Plus the results are different for SD and HD displays for the same size default font.
What is the algorithm for determining the length for the string ?
It does not take into account the font face, bold or italic, which causes text wrapping.
Plus the results are different for SD and HD displays for the same size default font.
What is the algorithm for determining the length for the string ?

RokuMarkn
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2013
02:01 PM
Re: Issues with roFont.getOneLineWidth
Could you clarify what you mean by "It does not take into account the font face, bold or italic"? This example shows that it returns different results when bold is used:
I will look into the issue with SD.
--Mark
BrightScript Debugger> reg = CreateObject("roFontRegistry")
BrightScript Debugger> font1 = reg.GetDefaultFont(32,false,false)
BrightScript Debugger> font2 = reg.GetDefaultFont(32,true,false)
BrightScript Debugger> ?font1.GetOneLineWidth("this string", 10000)
146
BrightScript Debugger> ?font2.GetOneLineWidth("this string", 10000)
166
I will look into the issue with SD.
--Mark
greubel
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2013
02:17 PM
Re: Issues with roFont.getOneLineWidth
It does. What I'm saying is that using that value will cause the text to wrap. Which makes it useless.
Working a a test routine, will post it soon.
Working a a test routine, will post it soon.