Bloc texts font size

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Bloc texts font size

Steven Costiou-2

Hi,

i am trying to set the font size of a BlTextElement, and i do not have much success. I use the following code to add the text element, where 'model' is a string.

First, if the string is '0.0' then the font size is correct (see screenshot). But, if for example the value is '21.0' then the font size is wrong (see the other screenshot). I don't understand, i've tried variants but it seems to me that this code was the right way to do it. Sometimes, a '9' would be displayed at the correct font size, sometimes not. Any ideas ?

text := BlTextElement new
        text:
            ((BrRopedText string: model)
                attributes:
                    {(BrTextForegroundAttribute paint: (Color green alpha: 0.8)).
                    (BrFontSizeAttribute size: 60).
                    (BrFontWeightAttribute weight: 50).
                    (BrFontGenericFamilyAttribute monospace).
                    "(BrFontFamilyAttribute named: 'Source Sans Pro')"});
        yourself.


    text
        constraintsDo: [ :c |
            c frame horizontal alignCenter.
            c frame vertical alignCenter ].
    

    "text is added to a parent BlElement"
    self addChild: text

Second, i don't have the impression that changing the font family does have any effect (but maybe its my local setup i don't know...).

Steven.


widget.png (11K) Download Attachment
widget-ok.png (11K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Bloc texts font size

Aliaksei Syrel
Hi Steven,

It is a known Cairo + Freetype bug. If you are on OSX try to install #development version of Bloc/Brick that uses Moz2D as rendering backend.
Cairo does not support named fonts because it there is no system fonts lookup. Moz2D supports it.

One way to fix strange font size is to apply scaling by 1.0001. Text measurement will still be broken, though...


Other than that you code looks good!

Cheers,
Alex

On 20 October 2017 at 15:04, Steven Costiou <[hidden email]> wrote:

Hi,

i am trying to set the font size of a BlTextElement, and i do not have much success. I use the following code to add the text element, where 'model' is a string.

First, if the string is '0.0' then the font size is correct (see screenshot). But, if for example the value is '21.0' then the font size is wrong (see the other screenshot). I don't understand, i've tried variants but it seems to me that this code was the right way to do it. Sometimes, a '9' would be displayed at the correct font size, sometimes not. Any ideas ?

text := BlTextElement new
        text:
            ((BrRopedText string: model)
                attributes:
                    {(BrTextForegroundAttribute paint: (Color green alpha: 0.8)).
                    (BrFontSizeAttribute size: 60).
                    (BrFontWeightAttribute weight: 50).
                    (BrFontGenericFamilyAttribute monospace).
                    "(BrFontFamilyAttribute named: 'Source Sans Pro')"});
        yourself.


    text
        constraintsDo: [ :c |
            c frame horizontal alignCenter.
            c frame vertical alignCenter ].
    

    "text is added to a parent BlElement"
    self addChild: text

Second, i don't have the impression that changing the font family does have any effect (but maybe its my local setup i don't know...).

Steven.


Reply | Threaded
Open this post in threaded view
|

Re: Bloc texts font size

Steven Costiou-2

Thanks Alex.

Not much success with this trick however, do you use scaleTo:, scaleBy:.. ? and on the BlTextElement or on the BrRopedText ?

It also seems that some sizes work better, like 45, 55, and 70 are ok aswell as everything under 40. I'll try to avoid the problematic sizes for the moment.

Unfortunately i am on linux and have trouble with brick and Moz2D, specifically on raspberry pi - but otherwise just bloc works fine so i'll stick with it for now :)

Steven.

Le 2017-10-20 19:52, Aliaksei Syrel a écrit :

Hi Steven,
 
It is a known Cairo + Freetype bug. If you are on OSX try to install #development version of Bloc/Brick that uses Moz2D as rendering backend.
Cairo does not support named fonts because it there is no system fonts lookup. Moz2D supports it.
 
One way to fix strange font size is to apply scaling by 1.0001. Text measurement will still be broken, though...
 
 
Other than that you code looks good!

Cheers,
Alex

On 20 October 2017 at 15:04, Steven Costiou <[hidden email]> wrote:

Hi,

i am trying to set the font size of a BlTextElement, and i do not have much success. I use the following code to add the text element, where 'model' is a string.

First, if the string is '0.0' then the font size is correct (see screenshot). But, if for example the value is '21.0' then the font size is wrong (see the other screenshot). I don't understand, i've tried variants but it seems to me that this code was the right way to do it. Sometimes, a '9' would be displayed at the correct font size, sometimes not. Any ideas ?

text := BlTextElement new
        text:
            ((BrRopedText string: model)
                attributes:
                    {(BrTextForegroundAttribute paint: (Color green alpha: 0.8)).
                    (BrFontSizeAttribute size: 60).
                    (BrFontWeightAttribute weight: 50).
                    (BrFontGenericFamilyAttribute monospace).
                    "(BrFontFamilyAttribute named: 'Source Sans Pro')"});
        yourself.


    text
        constraintsDo: [ :c |
            c frame horizontal alignCenter.
            c frame vertical alignCenter ].
    

    "text is added to a parent BlElement"
    self addChild: text

Second, i don't have the impression that changing the font family does have any effect (but maybe its my local setup i don't know...).

Steven.