CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15
  1. #1
    Join Date
    Jul 2001
    Location
    jordan
    Posts
    63

    text at any angle

    Hi
    Is there a simple way to rotate text using GDI?
    I know I know write to a Buffer or Memory DC and rotate then
    display, I wanna know if there's a faster way.

    thanks

    awni

  2. #2
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815

    Re: text at any angle

    Originally posted by awni
    Is there a simple way to rotate text using GDI?
    I know I know write to a Buffer or Memory DC and rotate then
    display, I wanna know if there's a faster way.
    Yes - when creating a font (either with ::CreateFont or CFont::CreateFont), you can specify an angle (in tenths of degrees) as the nOrientation parameter.

  3. #3
    Join Date
    Jul 2001
    Location
    jordan
    Posts
    63
    thank you , saved me more time than you think

    awni

  4. #4
    Join Date
    Jan 2004
    Location
    Earth
    Posts
    567
    Yes - when creating a font (either with ::CreateFont or CFont::CreateFont), you can specify an angle (in tenths of degrees) as the nOrientation parameter.
    Actually the nEscapement is responsible for the angle of a row of text. The escapement vector is parallel to the baseline of a row of characters. The escapement angle is the angle between the escapement vector and the x axis of a device. The orientation is the angle between each individual character and the x axis. On Win 95,98 and ME the orientation value is not used and the escapement specifies both the orientation and escapement (ususally the 2 are set to the same value). On Win 2000 and XP it is possible to specify each independently.

    TDM

  5. #5
    Join Date
    Jan 2004
    Location
    Earth
    Posts
    567
    See attached bitmap for a comparison between orientation and escapement.


    TDM
    Attached Images Attached Images

  6. #6
    Join Date
    Jul 2001
    Location
    jordan
    Posts
    63
    Thanks, i did use both escapement and orientation, I'm still trying
    to write the names of streets on a map. Streets are made up of segments and each segment needs the name written next to it, and the text needs to be at an angle. Some segments are too small, so no writing there.

    awni

  7. #7
    Join Date
    Mar 2004
    Posts
    23

    Re: text at any angle

    Hi,

    i have the problem that i need a font that has to be fully scalable (vector font) and rotateable... Can anyone help me with this...?

    Thank you!! :-)

  8. #8
    Join Date
    Apr 2002
    Location
    St.Petersburg, Russia
    Posts
    714

    Re: text at any angle

    Hi, awni.
    Few month ago I written the map program. I also encountered problem with font like this. After I tried this method (escapement and orientation), I developed my own font in file with my own format, that was simple to rotate to any angle with "rotate matrix". It's all because standart font was a little buggy. Also (I written map program for both PC and PocketPC) this method is wery slow (using my own font is about 10 times faster!).
    Also I added logical circles around letters. I put a letter in this place only if current letter is not overlapping another circles - this prevents overlapping letters.
    So, you can follow my steps.
    With best wishes, Alexander Hritonenkov

  9. #9
    Join Date
    Aug 2004
    Posts
    18

    Re: text at any angle

    Hi,
    For drawing text with any angle or other features,I think you need try the following MFC Source Code Flow/Diagram Kit:
    http://www.********.net/index.htm

    It includes all the features for drawing and manage shapes on the canvas.
    Regards

  10. #10
    Join Date
    Apr 2002
    Location
    St.Petersburg, Russia
    Posts
    714

    Re: text at any angle

    anwi, you can also look at TEXTFX sample from MSDN. Draw two lines and take a look to text, that appears between these lines.
    Sample attached.
    Attached Files Attached Files
    With best wishes, Alexander Hritonenkov

  11. #11
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: text at any angle

    Quote Originally Posted by jack_onlyone
    Hi,
    For drawing text with any angle or other features,I think you need try the following MFC Source Code Flow/Diagram Kit:
    http://www.********.net/index.htm

    It includes all the features for drawing and manage shapes on the canvas.
    Regards
    Could you please stop with posting this to each graphics problem! This is often not helpfull, as the mentioned diagram kit it not free (the cheapest license is more than $600) and spending $600 just to be able to draw rotated text is a bit too much, don't you think so...
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  12. #12
    Join Date
    May 2003
    Location
    Jodhpur -> Rajasthan -> INDIA
    Posts
    453

    Re: text at any angle

    Hello

    I used following code in order to get the vertical text, say mark on Y axis of scale to display Units of plot like Length (meter), etc

    But i landed up with just a line at the position of text, where it was supposed to start and move upwords.

    Sandeep Arya

    NOTE: I had even tried using 0 for nEscapement, but still things are same.
    Code:
    // This function will take care of drawing vertical label
    void CLabel::DrawVertical(CDC *pDC)
    {
      CFont Font;
      Font.CreateFont(m_FontSize,                   // nHeight
       		   0,                         // nWidth
    		   900,                         // nEscapement
    		   900,                         // nOrientation
    		   FW_NORMAL,                 // nWeight
    		   FALSE,                     // bItalic
    		   FALSE,                     // bUnderline
    		   0,                         // cStrikeOut
    		   ANSI_CHARSET,              // nCharSet
    		   OUT_DEFAULT_PRECIS,        // nOutPrecision
    		   CLIP_DEFAULT_PRECIS,       // nClipPrecision
    		   DEFAULT_QUALITY,           // nQuality
    		   DEFAULT_PITCH | FF_SWISS,  // nPitchAndFamily
    		   "Arial");
    	CFont *OldFont = pDC->SelectObject(&Font);
    	pDC->TextOut(m_Position.x, m_Position.y, m_Text);
    	pDC->SelectObject(OldFont);
    	Font.DeleteObject ();
    }
    Leave Your Mark Wherever You Go
    http://www.danasoft.com/sig/d0153030Sig.jpg

  13. #13
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: text at any angle

    Strange...
    Could you post a screenshot?
    Are you sure all variables have correct values?

    I just tried your code and got the result as you see in the screenshot below.
    Code:
        dc.SetBkMode(TRANSPARENT);
        CFont Font;
        Font.CreateFont(24,                   // nHeight
          0,                         // nWidth
          900,                         // nEscapement
          900,                         // nOrientation
          FW_NORMAL,                 // nWeight
          FALSE,                     // bItalic
          FALSE,                     // bUnderline
          0,                         // cStrikeOut
          ANSI_CHARSET,              // nCharSet
          OUT_DEFAULT_PRECIS,        // nOutPrecision
          CLIP_DEFAULT_PRECIS,       // nClipPrecision
          DEFAULT_QUALITY,           // nQuality
          DEFAULT_PITCH | FF_SWISS,  // nPitchAndFamily
          "Arial");
        CFont *OldFont = dc.SelectObject(&Font);
        dc.TextOut(100,100, "Test text");
        dc.SelectObject(OldFont);
        Font.DeleteObject ();
    Attached Images Attached Images
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  14. #14
    Join Date
    Oct 2004
    Posts
    12

    Re: text at any angle

    Please can any body explain hoy to achieve this rotarion in a pure Win32 not MFC, createfont does not exist in pure win32. Thanks a lot.

  15. #15
    Join Date
    Oct 2004
    Posts
    5

    Re: text at any angle

    I am sure tha t there is an API function CreateFont to do so.

    HFONT CreateFont(
    int nHeight, // logical height of font
    int nWidth, // logical average character width
    int nEscapement, // angle of escapement
    int nOrientation, // base-line orientation angle
    int fnWeight, // font weight
    DWORD fdwItalic, // italic attribute flag
    DWORD fdwUnderline, // underline attribute flag
    DWORD fdwStrikeOut, // strikeout attribute flag
    DWORD fdwCharSet, // character set identifier
    DWORD fdwOutputPrecision, // output precision
    DWORD fdwClipPrecision, // clipping precision
    DWORD fdwQuality, // output quality
    DWORD fdwPitchAndFamily, // pitch and family
    LPCTSTR lpszFace // pointer to typeface name string
    );

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured