[Mono-list] Text on Cairo

Francisco M. Marzoa fmmarzoa at gmx.net
Wed Nov 17 09:00:46 EST 2010


Hello Ian,

I've somethings more clear now after reading your code, anyway I want to
clearify my point. I will use the same terminology used in this tutorial:

http://www.mono-project.com/Mono.Cairo_Tutorial#Text

As you know and see, when you put sometext in Cairo in a given point by
its coordinates, that point mean to be at the left-bottom of the text
but over the descent, exactly as the baseline (quote: "The reference
point is always on the baseline").

But I rather like to use a reference point at the left-top of the text.

So I need to calculate the baseline reference point based on the
left-top point, that means to increment left-top.Y by the distance from
left-top.Y to baseline.Y.

At this time I cannot check it yet, but now I think that I must add at
least TextExtent.Height and probably something more.

I hope you understand.

Best regards,


El 16/11/10 21:46, Ian Norton escribió:
> Hi Francisco,
>
> As far as I know, text extends are to work out where the boundaries of
> your text will be after you write it, this is useful if you want to put
> several strings next to each other ( eg, write the next word or next
> line ). You would use the extends to find out how many cairo pixels tall
> the string would be.
>
> If you just want to print one string of text starting at a particular
> location on screen and don't need to know how wide or tall it ends up
> then you can safely do this:-
>
> public void StringAt( Context ctx, string str, int x, int y )
> {
>   ctx.NewPath();
>   ctx.Color = new Color( 0, 0, 0, 1 );
>   ctx.SetFontSize(12);
>   ctx.MoveTo(x,y);
>   ctx.ShowText(str);  
> }
>
>
> If you wanted to use extents to find the boundaries of your text you
> might do this:
>
> public void StringsInRows( Context ctx, string[] strlist, int x, int y )
> {
>   var next_y = y;
>   // print strings in lines
>   foreach ( var str in strlist ){
>     ctx.NewPath();
>     ctx.Color = new Color( 0, 0, 0, 1 );
>     ctx.SetFontSize(12); 
>     ctx.MoveTo(x,next_y);
>
>     var extent = ctx.TextExtents(str);
>     next_y += (extent.Height + 5); // next line will be 5px under this
> line
>     ctx.ShowText(str);  
>   }
>
> }
>
> Hope that helps
>
> Regards
>
> Ian
>
> On Tue, 2010-11-16 at 17:21 +0000, Francisco M. Marzoa wrote:
>   
>> Hello there,
>>
>> I'm currently fighting with Cairo's text system, and I should to admit
>> that I've a slight headache...
>>
>> The main problem that I've is that, for coherence, I would like to
>> specify a point (as a pair of x,y coords) and the text should be drawn
>> taken that point like the top-left point of the text.
>>
>> I think I must use TextExtents and/or FontExtents for this purpouse, but
>> I didn't figure out HOW.
>>
>> There's an explanation in this tutorial:
>>
>> http://www.mono-project.com/Mono.Cairo_Tutorial#Understanding_Text
>>
>> But unfortunatly the code is missing.
>>
>> Does someone has some code on this issue that he/she dont mind to share???
>>
>> Thanks a lot in advance,
>>
>>
>> _______________________________________________
>> Mono-list maillist  -  Mono-list at lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/mono-list
>>     
>
>
>   



More information about the Mono-list mailing list