Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Drawing strings on GDI+ that are vertical bottom to top aligned!

Drawing strings on GDI+ that are vertical bottom to top aligned!

Scheduled Pinned Locked Moved C / C++ / MFC
graphicswinformsquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Williams
    wrote on last edited by
    #1

    Hi, How can I draw strings with GDI+ that are are vertical bottom to top aligned! I try things as SetFormat(StringFormatFlagsDirectionVertical | StringFormatFlagsDirectionRightToLeft) but the text is always top to bottom oriented.

    J 1 Reply Last reply
    0
    • W Williams

      Hi, How can I draw strings with GDI+ that are are vertical bottom to top aligned! I try things as SetFormat(StringFormatFlagsDirectionVertical | StringFormatFlagsDirectionRightToLeft) but the text is always top to bottom oriented.

      J Offline
      J Offline
      Jonathan de Halleux
      wrote on last edited by
      #2

      Yep, that's a serious limitation of GDI+ but it can be easily overpassed by rotating yourself the text:

      // defined somewhere
      Graphics* m_pGraphics;

      What you have to do is : 1. translate text to origin, 2. rotate, 3. translate back to position, Let's go: We create a graphic container to apply transformations

      graphicsContainer = m_pGraphics->BeginContainer();

      Doing steps 1,2,3 the order of matrix multiplication is important !

      m\_pGraphics->TranslateTransform(pointF.X,pointF.Y);
      // angle is the angle you want to rotate your text in CCW turn with 0 = horizontal. Of course, in GDI+, Microsoft uses
      // CW angle so it is not compatible with trigonometric functions :(
      m\_pGraphics->RotateTransform(-angle);
      m\_pGraphics->TranslateTransform(-pointF.X,-pointF.Y);
      

      Draw the string

      m\_pGraphics->DrawString(str, -1, &font, pointF, &sf,&solidBrush);
      

      Fold back transformations by getting out of the container

      m_pGraphics->EndContainer(graphicsContainer);

      Jonathan de Halleux, Belgium.

      W 1 Reply Last reply
      0
      • J Jonathan de Halleux

        Yep, that's a serious limitation of GDI+ but it can be easily overpassed by rotating yourself the text:

        // defined somewhere
        Graphics* m_pGraphics;

        What you have to do is : 1. translate text to origin, 2. rotate, 3. translate back to position, Let's go: We create a graphic container to apply transformations

        graphicsContainer = m_pGraphics->BeginContainer();

        Doing steps 1,2,3 the order of matrix multiplication is important !

        m\_pGraphics->TranslateTransform(pointF.X,pointF.Y);
        // angle is the angle you want to rotate your text in CCW turn with 0 = horizontal. Of course, in GDI+, Microsoft uses
        // CW angle so it is not compatible with trigonometric functions :(
        m\_pGraphics->RotateTransform(-angle);
        m\_pGraphics->TranslateTransform(-pointF.X,-pointF.Y);
        

        Draw the string

        m\_pGraphics->DrawString(str, -1, &font, pointF, &sf,&solidBrush);
        

        Fold back transformations by getting out of the container

        m_pGraphics->EndContainer(graphicsContainer);

        Jonathan de Halleux, Belgium.

        W Offline
        W Offline
        Williams
        wrote on last edited by
        #3

        Very thanks friend. It´s really what I was thinking to do. Thanks for your help!:)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups