Discussion:
[cairo] Cairo text - underlined and striked text
WebSTAR Corp.
2018-06-13 07:13:23 UTC
Permalink
Hi All,

I would have a question on you:

I use Cairo Graphics (1.10.2) on a Visual Studio project.
Because Cairo doesn't have functions for underlined and striked text, I tried to use "cairo_win32_font_face_create_for_hfont" to create a font from a Windows HFONT object that supports both underlined and striked text.
The problem is, even if I set underlined & striked text to "TRUE" in the HFONT object, the text is still not unerlined or striked. Is this a normal behavior?

This is some code:


HFONT hFont;
hFont = CreateFont(48, 0, 0, 0, FW_DONTCARE, TRUE, TRUE, TRUE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, TEXT("Impact"));

cairo_font_face_t* fontFace = cairo_win32_font_face_create_for_hfont(hFont);

cairo_set_font_face(cr, fontFace);

cairo_set_font_size(cr, fontSize);
cairo_set_source_rgb(cr, 0.37, 0.37, 0.37);

cairo_move_to(cr, x, y);
cairo_show_text(cr, myText);

cairo_font_face_destroy(fontFace);
DeleteObject(hFont);


PS: Is there a way to create underlined & striked text on Cairo?

Many thanks,
Michael.
--
cairo mailing list
***@cairographics.org
https://lis
Bryce Harrington
2018-06-13 16:06:49 UTC
Permalink
Post by WebSTAR Corp.
Hi All,
I use Cairo Graphics (1.10.2) on a Visual Studio project.
Because Cairo doesn't have functions for underlined and striked text, I tried to use "cairo_win32_font_face_create_for_hfont" to create a font from a Windows HFONT object that supports both underlined and striked text.
The problem is, even if I set underlined & striked text to "TRUE" in the HFONT object, the text is still not unerlined or striked. Is this a normal behavior?
HFONT hFont;
hFont = CreateFont(48, 0, 0, 0, FW_DONTCARE, TRUE, TRUE, TRUE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, TEXT("Impact"));
cairo_font_face_t* fontFace = cairo_win32_font_face_create_for_hfont(hFont);
cairo_set_font_face(cr, fontFace);
cairo_set_font_size(cr, fontSize);
cairo_set_source_rgb(cr, 0.37, 0.37, 0.37);
cairo_move_to(cr, x, y);
cairo_show_text(cr, myText);
cairo_font_face_destroy(fontFace);
DeleteObject(hFont);
PS: Is there a way to create underlined & striked text on Cairo?
Have you tried Pango for this? The cairo_show_text() and friends are
convenient but limited in functionality. See:

https://cairographics.org/manual/cairo-text.html#cairo-show-text

Bryce
--
cairo mailing list
***@cairographics.org
https:/
Uli Schlachter
2018-06-13 18:02:50 UTC
Permalink
Hi,
Post by WebSTAR Corp.
PS: Is there a way to create underlined & striked text on Cairo?
Uhm, you can get the text dimensions from Cairo. Just draw a line where
the baseline is for underlining. For strike-through use the logical
height of the font and draw the line at the center of the text? (i.e.
baseline plus half the font height to the top)

But yeah, as Bryce wrote in that other mail, Pango is the way to go for
advanced font- and text-related things.

Cheers,
Uli
--
- He wants the impossible...!
- That's the short definition of 'captain'.
--
cairo mailing list
***@cairographics.org
http
WebSTAR Corp.
2018-06-14 17:02:37 UTC
Permalink
Bryce, Uli, Thank you for the answers!
I tought that I do something wrong.

Best,
Michael.

--------------------------------------------
On Wed, 6/13/18, Bryce Harrington <***@bryceharrington.org> wrote:

Subject: Re: [cairo] Cairo text - underlined and striked text
To: "WebSTAR Corp." <***@yahoo.com>
Cc: ***@cairographics.org
Date: Wednesday, June 13, 2018, 6:06 PM

On Wed, Jun 13, 2018 at 07:13:23AM +0000,
Post by WebSTAR Corp.
Hi All,
I would have a
question on you:
I use Cairo Graphics (1.10.2) on a Visual Studio project.
Post by WebSTAR Corp.
Because Cairo doesn't have functions
for underlined and striked text, I tried to use
"cairo_win32_font_face_create_for_hfont" to create
a font from a Windows HFONT object that supports both
underlined and striked text.
Post by WebSTAR Corp.
The
problem is, even if I set underlined & striked text to
"TRUE" in the HFONT object, the text is still not
unerlined or striked. Is this a normal behavior?
Post by WebSTAR Corp.
This is some
HFONT hFont;
hFont =
CreateFont(48, 0, 0, 0, FW_DONTCARE, TRUE, TRUE, TRUE,
DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS,
CLEARTYPE_QUALITY, VARIABLE_PITCH,
TEXT("Impact"));
Post by WebSTAR Corp.
cairo_font_face_t* fontFace =
cairo_win32_font_face_create_for_hfont(hFont);
cairo_set_font_face(cr, fontFace);
Post by WebSTAR Corp.
cairo_set_font_size(cr, fontSize);
cairo_set_source_rgb(cr, 0.37, 0.37,
0.37);
cairo_move_to(cr, x, y);
cairo_show_text(cr, myText);
Post by WebSTAR Corp.
cairo_font_face_destroy(fontFace);
DeleteObject(hFont);
PS: Is there a
way to create underlined & striked text on
Cairo?

Have you tried
Pango for this?  The cairo_show_text() and friends are
convenient but limited in functionality. 
See:

https://cairographics.org/manual/cairo-text.html#cairo-show-text

Bryce

-----Inline Attachment Follows-----
--
cairo mailing list
***@cairographics.org
https://lists.cairograph
Loading...