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. Correct font size

Correct font size

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
5 Posts 3 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.
  • J Offline
    J Offline
    Jim Crafton
    wrote on last edited by
    #1

    I have a window that needs to display text using a fixed size (mono spaced) TT font (say Courier New) and the text will be limited to 80 columns by 24 rows. I need to calculate the bounding rect that keeps the aspect ratio of the font and centers it in the window. I can get all this to work fine. The next problem is choosing the font size. How do I get windows to give me a font size that will correctly fill this rect? Is this not possible? It seems no matter what I do, I get font sizes that do not scale up or down smoothly, and the text is usually either too small or too big. ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF!

    O I 2 Replies Last reply
    0
    • J Jim Crafton

      I have a window that needs to display text using a fixed size (mono spaced) TT font (say Courier New) and the text will be limited to 80 columns by 24 rows. I need to calculate the bounding rect that keeps the aspect ratio of the font and centers it in the window. I can get all this to work fine. The next problem is choosing the font size. How do I get windows to give me a font size that will correctly fill this rect? Is this not possible? It seems no matter what I do, I get font sizes that do not scale up or down smoothly, and the text is usually either too small or too big. ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF!

      O Offline
      O Offline
      oshah
      wrote on last edited by
      #2

      The MidiPlyr PSDK sample has code which scales the timer text so it fills the window (not very well mind you). It's located in Samples/Multimedia/Audio/MidiPlyr/uiutils.c:EmbossedTextOut() and CreateScaledFont(). 80% chance that the scaled font feature (and all of uiutils.c) was created as an extra credit assignment. But anyway, the API to use is GetTextExtentPoint32. -- modified at 11:43 Thursday 9th March, 2006

      J 1 Reply Last reply
      0
      • O oshah

        The MidiPlyr PSDK sample has code which scales the timer text so it fills the window (not very well mind you). It's located in Samples/Multimedia/Audio/MidiPlyr/uiutils.c:EmbossedTextOut() and CreateScaledFont(). 80% chance that the scaled font feature (and all of uiutils.c) was created as an extra credit assignment. But anyway, the API to use is GetTextExtentPoint32. -- modified at 11:43 Thursday 9th March, 2006

        J Offline
        J Offline
        Jim Crafton
        wrote on last edited by
        #3

        Thanks. I know about GetTextExtentPoint32. Unfortunately the problem is getting windows to use a reasonable font size. It appears that windows only has a few font sizes, and there's no provision or way to smoothly scale up or down without jumps in sizes. This means that sometimes the font matches the rect just fine, others it's too small, and other times it's too big. I'll look into the example though! ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF!

        O 1 Reply Last reply
        0
        • J Jim Crafton

          I have a window that needs to display text using a fixed size (mono spaced) TT font (say Courier New) and the text will be limited to 80 columns by 24 rows. I need to calculate the bounding rect that keeps the aspect ratio of the font and centers it in the window. I can get all this to work fine. The next problem is choosing the font size. How do I get windows to give me a font size that will correctly fill this rect? Is this not possible? It seems no matter what I do, I get font sizes that do not scale up or down smoothly, and the text is usually either too small or too big. ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF!

          I Offline
          I Offline
          includeh10
          wrote on last edited by
          #4

          a little bit confused by ur post: every row must contain 80 characters or differnt (max is 80)? all rows use same font? "display" means by paint (CDC etc) or text control (CEdit etc)?


          A nice tool for optimizing your Microsoft html-help contents. Includeh10

          1 Reply Last reply
          0
          • J Jim Crafton

            Thanks. I know about GetTextExtentPoint32. Unfortunately the problem is getting windows to use a reasonable font size. It appears that windows only has a few font sizes, and there's no provision or way to smoothly scale up or down without jumps in sizes. This means that sometimes the font matches the rect just fine, others it's too small, and other times it's too big. I'll look into the example though! ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF!

            O Offline
            O Offline
            oshah
            wrote on last edited by
            #5

            The MidiPlyr sample also has this problem. It doesn't fully scale to the window, hence the jumps in font size you see. So if Microsoft, for all their wealth, power and unrestricted access to the Windows source code, can't get it right, what hope do we poor insignificant developers who get the scrap heap public API, have :)?

            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