Draw vertical text using GDI+ stringFormat

Discussions related to Visual Prolog
Harrison Pratt
VIP Member
Posts: 320
Joined: 5 Nov 2000 0:01

Draw vertical text using GDI+ stringFormat

Unread post by Harrison Pratt » 12 Jul 2020 21:43

Is vertical text output supported in the graphics class?
I cannot find ViP documentation on this feature, but it is defined in MSDN:
https://docs.microsoft.com/en-us/window ... g-text-use

Code: Select all

... Formatter = stringFormat::create(), % ??? How to set a format flag in Formatter for vertical text here ??? G:drawString(axisLabel, Font, CtrlRectF, Formatter, Brush), ...
I can get the job done in a kludgy way by interleaving carriage returns between the characters of the string, but it would be more robust to use stringFormat.

User avatar
Thomas Linder Puls
VIP Member
Posts: 1168
Joined: 28 Feb 2000 0:01

Re: Draw vertical text using GDI+ stringFormat

Unread post by Thomas Linder Puls » 12 Jul 2020 23:10

This is more or less a direct translation of the code from the Microsoft example (however using a rectF rather than a pointF):

Code: Select all

predicates     onPaint : window::paintresponder. clauses     onPaint(_, _, GDI) :-         HDC = GDI:getNativeGraphicContext(IsReleaseNeeded),         Graphics = graphics::createFromHDC(HDC),         FontFamily = fontFamily::createFromName("Lucida Console"),         Font = font::createFromFontFamily(FontFamily, 14, gdiplus_native::fontStyleRegular, gdiplus_native::unitPoint),         RectF = gdiplus::rectF(40, 10, 50, 110),         StringFormat = stringFormat::create(),         StringFormat:formatFlags := gdiplus_native::stringFormatFlagsDirectionVertical,         SolidBrush = solidBrush::create(color::create(255, 0, 0, 255)),         Graphics:drawString("Vertical text", Font, RectF, StringFormat, SolidBrush),         Graphics:delete(),         GDI:releaseNativeGraphicContext(HDC, IsReleaseNeeded).
Regards Thomas Linder Puls
PDC

Harrison Pratt
VIP Member
Posts: 320
Joined: 5 Nov 2000 0:01

Re: Draw vertical text using GDI+ stringFormat

Unread post by Harrison Pratt » 13 Jul 2020 1:57

Ahhh ... thank you.

I searched high and low for that constant in all the wrong places! :D

User avatar
Thomas Linder Puls
VIP Member
Posts: 1168
Joined: 28 Feb 2000 0:01

Re: Draw vertical text using GDI+ stringFormat

Unread post by Thomas Linder Puls » 13 Jul 2020 20:54

A little tip that would surely have found it for you.

Paste the constant from the example into the editor and use the menu Insert -> Qualification (or Ctrl+Shift+S)
Insert Qualification.png
Insert Qualification.png (4.85 KiB) Viewed 1376 times
If the constant is known (the relevant package must have been compiled) then the qualification will turn up.

Next (with the caret after the constant) press Ctrl+Space to get the the completion window up:
completion.png
completion.png (13.36 KiB) Viewed 1376 times
Now TAB will change the casing to match the declaration (including changing the first letter to lowercase).
Regards Thomas Linder Puls
PDC

Harrison Pratt
VIP Member
Posts: 320
Joined: 5 Nov 2000 0:01

Re: Draw vertical text using GDI+ stringFormat

Unread post by Harrison Pratt » 14 Jul 2020 12:03

I use the very handy Ctrl-Shift-S approach often.

What happened when I was trying to find the constant (stringFormatFlagsDirectionVertical) was that I wrongly assumed I would find it in the pfc\gui directory tree and searched files there for the substring "vertical" using Ctrl-Shift-F.

The constant is defined in pfc\windowsApi\gdiplus_api folder so I didn't search the proper directory tree!

Moral to the story: Search the entire pfc directory tree when you don't find what you seek.

Post Reply