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. Zooming a text

Zooming a text

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelpannouncement
4 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.
  • D Offline
    D Offline
    Dimitris Vikeloudas
    wrote on last edited by
    #1

    I have a CEdit control and I would like to be able to zoom the text by a floating factor (i.e 0.75 or 1.25 for 80% or 100% zoom). I manage to resize the box to shrink or expand depending on the factor. However, I cannot get a scaled text. I tried the following code // Scale the window. XFORM xForm; xForm.eM11 = xForm.eM22 = (FLOAT)m_rZoomingFactor; xForm.eM12 = xForm.eM21 = xForm.eDx = xForm.eDy = (FLOAT)0.0; HDC hDC = this->GetWindowDC()->GetSafeHdc(); SetGraphicsMode(hDC, GM_ADVANCED); ModifyWorldTransform( hDC, &xForm, MWT_LEFTMULTIPLY ); either by calling it directly or by placing it inside the OnPaint message handler but I get no change. I also thought that I may need to change the existing font. However, I looked to CFont class and to LOGFONT structure and I haven't seen a simple way to get a font which is a zoomed version of the current font. How can I zoom a text in a CEdit control? Can I do it but somehow scaling the device context or should I change the font? How do I get a scaled version of the current font? Note that this change may happen on fly. I 'd like to be able whilst the user is editing the text to zoom in and out. Resizing the box is not a problem but zooming the text is.

    C 1 Reply Last reply
    0
    • D Dimitris Vikeloudas

      I have a CEdit control and I would like to be able to zoom the text by a floating factor (i.e 0.75 or 1.25 for 80% or 100% zoom). I manage to resize the box to shrink or expand depending on the factor. However, I cannot get a scaled text. I tried the following code // Scale the window. XFORM xForm; xForm.eM11 = xForm.eM22 = (FLOAT)m_rZoomingFactor; xForm.eM12 = xForm.eM21 = xForm.eDx = xForm.eDy = (FLOAT)0.0; HDC hDC = this->GetWindowDC()->GetSafeHdc(); SetGraphicsMode(hDC, GM_ADVANCED); ModifyWorldTransform( hDC, &xForm, MWT_LEFTMULTIPLY ); either by calling it directly or by placing it inside the OnPaint message handler but I get no change. I also thought that I may need to change the existing font. However, I looked to CFont class and to LOGFONT structure and I haven't seen a simple way to get a font which is a zoomed version of the current font. How can I zoom a text in a CEdit control? Can I do it but somehow scaling the device context or should I change the font? How do I get a scaled version of the current font? Note that this change may happen on fly. I 'd like to be able whilst the user is editing the text to zoom in and out. Resizing the box is not a problem but zooming the text is.

      C Offline
      C Offline
      Chris Meech
      wrote on last edited by
      #2

      Dimitris Vikeloudas wrote:

      I haven't seen a simple way to get a font which is a zoomed version of the current font.

      If you can obtain the LOGFONT structure of the font that the CEdit control uses, the create a font that has an increased point size by your zoom factor, then do a set font call on the CEdit control and then invalidate the window to get it repainted. You will also have to delete the font you created, otherwise it will leak.

      Chris Meech I am Canadian. [heard in a local bar] Nobody likes jerks. [espeir] The zen of the soapbox is hard to attain...[Jörgen Sigvardsson] I wish I could remember what it was like to only have a short term memory.[David Kentley]

      D 1 Reply Last reply
      0
      • C Chris Meech

        Dimitris Vikeloudas wrote:

        I haven't seen a simple way to get a font which is a zoomed version of the current font.

        If you can obtain the LOGFONT structure of the font that the CEdit control uses, the create a font that has an increased point size by your zoom factor, then do a set font call on the CEdit control and then invalidate the window to get it repainted. You will also have to delete the font you created, otherwise it will leak.

        Chris Meech I am Canadian. [heard in a local bar] Nobody likes jerks. [espeir] The zen of the soapbox is hard to attain...[Jörgen Sigvardsson] I wish I could remember what it was like to only have a short term memory.[David Kentley]

        D Offline
        D Offline
        Dimitris Vikeloudas
        wrote on last edited by
        #3

        I can obtain the LOGFONT and I know how to handle the font that I 've created. My problem with the LOGFONT (and the CFont class) is that having the structure I do know in which fields should my zooming factor applied (I assume multiplied) to get a bigger or smaller font aesthetically pleasing. Any help on that please? I thought that another way doing that could be applying a transformation to the device context of the CEdit window (maybe using the ModifyWorldTransform to scale it?) but it does not seems to affect the text in a CEdit. Is it possible to scale a CEdit window??

        C 1 Reply Last reply
        0
        • D Dimitris Vikeloudas

          I can obtain the LOGFONT and I know how to handle the font that I 've created. My problem with the LOGFONT (and the CFont class) is that having the structure I do know in which fields should my zooming factor applied (I assume multiplied) to get a bigger or smaller font aesthetically pleasing. Any help on that please? I thought that another way doing that could be applying a transformation to the device context of the CEdit window (maybe using the ModifyWorldTransform to scale it?) but it does not seems to affect the text in a CEdit. Is it possible to scale a CEdit window??

          C Offline
          C Offline
          Chris Meech
          wrote on last edited by
          #4

          The first field of the LOGFONT structure is height. Increase this using your zoom factor and set the second field, the width, to NULL. The call to CreateFont will calculate an appropriate width, I believe.

          Chris Meech I am Canadian. [heard in a local bar] Nobody likes jerks. [espeir] The zen of the soapbox is hard to attain...[Jörgen Sigvardsson] I wish I could remember what it was like to only have a short term memory.[David Kentley]

          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