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. Widest Character and Height of the character

Widest Character and Height of the character

Scheduled Pinned Locked Moved C / C++ / MFC
10 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
    shiv nand
    wrote on last edited by
    #1

    I want to know the widest character and height of "MS Sans Sarif" Font Type. The Characters = {abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ},font size may be in between 8 to 50.

    E M 2 Replies Last reply
    0
    • S shiv nand

      I want to know the widest character and height of "MS Sans Sarif" Font Type. The Characters = {abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ},font size may be in between 8 to 50.

      E Offline
      E Offline
      Eugen Podsypalnikov
      wrote on last edited by
      #2

      Try it :) :

      CSize GetMaxCharSize(CDC* pcDC, CFont* pcFont)
      {
      CSize csizeResult(0, 0);
      if (pcDC && pcFont) {
      CGdiObject* pcOldFont = pcDC->SelectObject(pcFont);
      TEXTMETRIC tm = {0};
      pDC->GetTextMetrics(&tm);
      csizeResult.cx = tm.tmMaxCharWidth;
      csizeResult.cy = tm.tmHeight;
      pcDC->SelectObject(pcOldFont);
      }
      return csizeResult;
      }

      virtual void BeHappy() = 0;

      A S 2 Replies Last reply
      0
      • E Eugen Podsypalnikov

        Try it :) :

        CSize GetMaxCharSize(CDC* pcDC, CFont* pcFont)
        {
        CSize csizeResult(0, 0);
        if (pcDC && pcFont) {
        CGdiObject* pcOldFont = pcDC->SelectObject(pcFont);
        TEXTMETRIC tm = {0};
        pDC->GetTextMetrics(&tm);
        csizeResult.cx = tm.tmMaxCharWidth;
        csizeResult.cy = tm.tmHeight;
        pcDC->SelectObject(pcOldFont);
        }
        return csizeResult;
        }

        virtual void BeHappy() = 0;

        A Offline
        A Offline
        Adam Roderick J
        wrote on last edited by
        #3

        I support the above. :)

        Величие не Бога может быть недооценена.

        1 Reply Last reply
        0
        • E Eugen Podsypalnikov

          Try it :) :

          CSize GetMaxCharSize(CDC* pcDC, CFont* pcFont)
          {
          CSize csizeResult(0, 0);
          if (pcDC && pcFont) {
          CGdiObject* pcOldFont = pcDC->SelectObject(pcFont);
          TEXTMETRIC tm = {0};
          pDC->GetTextMetrics(&tm);
          csizeResult.cx = tm.tmMaxCharWidth;
          csizeResult.cy = tm.tmHeight;
          pcDC->SelectObject(pcOldFont);
          }
          return csizeResult;
          }

          virtual void BeHappy() = 0;

          S Offline
          S Offline
          shiv nand
          wrote on last edited by
          #4

          please give me an example ?

          E 1 Reply Last reply
          0
          • S shiv nand

            please give me an example ?

            E Offline
            E Offline
            Eugen Podsypalnikov
            wrote on last edited by
            #5

            It could be something like this :) :

            /*virtual*/ void CYourView::OnInitialUpdate()
            {
            CBaseOfYourView::OnInitialUpdate();

            /*CFont*/ m_cFont.CreatePointFont(120, _T("Arial")); // 12pts * 10
            ...
            }

            /*virtual*/ void CYourView::OnDraw(CDC* pDC)
            {
            CSize cMaxCharSize(GetMaxCharSize(pDC, &m_cFont));
            CRect cMaxCharRect(CPoint(100, 100), cMaxCharSize);
            pDC->FillSolidRect(cMaxCharRect, RGB(0, 128, 200));
            ...
            }

            virtual void BeHappy() = 0;

            S 1 Reply Last reply
            0
            • E Eugen Podsypalnikov

              It could be something like this :) :

              /*virtual*/ void CYourView::OnInitialUpdate()
              {
              CBaseOfYourView::OnInitialUpdate();

              /*CFont*/ m_cFont.CreatePointFont(120, _T("Arial")); // 12pts * 10
              ...
              }

              /*virtual*/ void CYourView::OnDraw(CDC* pDC)
              {
              CSize cMaxCharSize(GetMaxCharSize(pDC, &m_cFont));
              CRect cMaxCharRect(CPoint(100, 100), cMaxCharSize);
              pDC->FillSolidRect(cMaxCharRect, RGB(0, 128, 200));
              ...
              }

              virtual void BeHappy() = 0;

              S Offline
              S Offline
              shiv nand
              wrote on last edited by
              #6

              thank you

              1 Reply Last reply
              0
              • S shiv nand

                I want to know the widest character and height of "MS Sans Sarif" Font Type. The Characters = {abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ},font size may be in between 8 to 50.

                M Offline
                M Offline
                Michel Godfroid
                wrote on last edited by
                #7

                http://msdn.microsoft.com/en-us/library/xwf9s90b(VS.71).aspx[^] In Western European fonts, the widest character is usually capital letter M (that's why typesetters refer to em-height and em-width). Most fonts will contain a character call em_space, which is a space that is exactly as wide as the widest character in the font.

                E 1 Reply Last reply
                0
                • M Michel Godfroid

                  http://msdn.microsoft.com/en-us/library/xwf9s90b(VS.71).aspx[^] In Western European fonts, the widest character is usually capital letter M (that's why typesetters refer to em-height and em-width). Most fonts will contain a character call em_space, which is a space that is exactly as wide as the widest character in the font.

                  E Offline
                  E Offline
                  Eugen Podsypalnikov
                  wrote on last edited by
                  #8

                  Please compare them :) : - W - M

                  virtual void BeHappy() = 0;

                  M S 2 Replies Last reply
                  0
                  • E Eugen Podsypalnikov

                    Please compare them :) : - W - M

                    virtual void BeHappy() = 0;

                    M Offline
                    M Offline
                    Michel Godfroid
                    wrote on last edited by
                    #9

                    That's why I said 'usually' ;-) em-space (or em_dash) should still be valid, though... http://en.wikipedia.org/wiki/Em_(typography)[^]

                    1 Reply Last reply
                    0
                    • E Eugen Podsypalnikov

                      Please compare them :) : - W - M

                      virtual void BeHappy() = 0;

                      S Offline
                      S Offline
                      shiv nand
                      wrote on last edited by
                      #10

                      how to compare W and M

                      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