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. Find the width of unicode data

Find the width of unicode data

Scheduled Pinned Locked Moved C / C++ / MFC
json
4 Posts 4 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.
  • S Offline
    S Offline
    ShilpiP
    wrote on last edited by
    #1

    I am trying to find out the width of data that is writtern in unicode.Is there any API for this. I find GetTextMetrices but it does not give me correct width for unicode true type font. Thanks in Advance :)

    Yes U Can ...If U Can ,Dream it , U can do it ...ICAN

    K D PJ ArendsP 3 Replies Last reply
    0
    • S ShilpiP

      I am trying to find out the width of data that is writtern in unicode.Is there any API for this. I find GetTextMetrices but it does not give me correct width for unicode true type font. Thanks in Advance :)

      Yes U Can ...If U Can ,Dream it , U can do it ...ICAN

      K Offline
      K Offline
      KarstenK
      wrote on last edited by
      #2

      Check that all is written in Unicode. Maybe you havent supported the font name properly :confused: Some code to look at it would be nice.

      Greetings from Germany

      1 Reply Last reply
      0
      • S ShilpiP

        I am trying to find out the width of data that is writtern in unicode.Is there any API for this. I find GetTextMetrices but it does not give me correct width for unicode true type font. Thanks in Advance :)

        Yes U Can ...If U Can ,Dream it , U can do it ...ICAN

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        Shilpi Boosar wrote:

        I find GetTextMetrices but it does not give me correct width for unicode true type font.

        How are you using it?

        "Love people and use things, not love things and use people." - Unknown

        "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

        1 Reply Last reply
        0
        • S ShilpiP

          I am trying to find out the width of data that is writtern in unicode.Is there any API for this. I find GetTextMetrices but it does not give me correct width for unicode true type font. Thanks in Advance :)

          Yes U Can ...If U Can ,Dream it , U can do it ...ICAN

          PJ ArendsP Offline
          PJ ArendsP Offline
          PJ Arends
          wrote on last edited by
          #4

          If GetTextMetrics does not return the proper width, which it does not for some fonts such as ALISON, then one should use the GetCharABCWidthsFloat function.

          RECT ImageRect = {0};
          
          // get the required height of the bitmap
          TEXTMETRIC tm = {0};
          GetTextMetrics(ImageDC, &tm);
          ImageRect.bottom = tm.tmHeight;
          
          // Calculate the required width of the bitmap. Some characters in some fonts
          // have overhangs and/or underhangs so large that the second or even third
          // character from either end of the text can affect the size of the bitmap
          // needed to display the text.
          ABCFLOAT ABCWidths = {0};
          double left = 0.0;
          double right = 0.0;
          double pos = 0.0;
          
          for (std::tstring::iterator it = ImageText.begin(); it != ImageText.end(); ++it)
          {
              if (GetCharABCWidthsFloat(ImageDC, \*(it), \*(it), &ABCWidths))
              {
                  pos += ABCWidths.abcfA;
                  left = min(left, pos);
                  pos += ABCWidths.abcfB;
                  right = max(right, pos);
                  pos += ABCWidths.abcfC;
              }
          }
          
          ImageRect.right = (long)((right - left) + 0.5);
          

          You may be right I may be crazy -- Billy Joel -- Within you lies the power for good - Use it!

          Within you lies the power for good; Use it!

          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