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. The Lounge
  3. Oh come on Microsoft!

Oh come on Microsoft!

Scheduled Pinned Locked Moved The Lounge
graphicscsharpapachewinformstools
15 Posts 6 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.
  • H honey the codewitch

    My little graphics library needs to do text, and I thought "hey, I'll whip up a C# app to rasterize monospaced fonts to a monochrome bitmap." Just add a reference to System.Drawing to a console app, and then create a Bitmap and draw to it right? Wrong. Even after you set all of the text rendering hints, and even using GraphicsPath.AddString() for more accuracy, you cannot turn off the padding around the fonts, nor get the font to a pixel perfect height at all sizes. The thing is, the GDI+ code underneath is perfectly capable of doing this. They just didn't expose it. The alternative is reinventing the entire elephanting wheel and rasterizing the fonts myself. I found an open source project (under Apache license unfortunately) that I can use to build my tool. Fortunately that tool isn't part of my GFX package itself - it's just a utility to make files that the GFX code can read. But this shouldn't be necessary. They actually have to parse the TTFs and draw them manually. X|

    Real programmers use butterflies

    CPalliniC Offline
    CPalliniC Offline
    CPallini
    wrote on last edited by
    #4

    Quote:

    The thing is, the GDI+ code underneath is perfectly capable of doing this. They just didn't expose i

    Then write a C++ program using Winapi & GDI+. I experienced myself the problem you have with C# and found it quite annoying. Eventually I used a free tool (unfortunately I don't remember its name) to rasterize the fonts.

    "In testa che avete, Signor di Ceprano?" -- Rigoletto

    In testa che avete, signor di Ceprano?

    H 1 Reply Last reply
    0
    • H honey the codewitch

      My little graphics library needs to do text, and I thought "hey, I'll whip up a C# app to rasterize monospaced fonts to a monochrome bitmap." Just add a reference to System.Drawing to a console app, and then create a Bitmap and draw to it right? Wrong. Even after you set all of the text rendering hints, and even using GraphicsPath.AddString() for more accuracy, you cannot turn off the padding around the fonts, nor get the font to a pixel perfect height at all sizes. The thing is, the GDI+ code underneath is perfectly capable of doing this. They just didn't expose it. The alternative is reinventing the entire elephanting wheel and rasterizing the fonts myself. I found an open source project (under Apache license unfortunately) that I can use to build my tool. Fortunately that tool isn't part of my GFX package itself - it's just a utility to make files that the GFX code can read. But this shouldn't be necessary. They actually have to parse the TTFs and draw them manually. X|

      Real programmers use butterflies

      S Offline
      S Offline
      Storm blade
      wrote on last edited by
      #5

      A C# wrapper around FreeType is another alternative?

      H 1 Reply Last reply
      0
      • S Storm blade

        A C# wrapper around FreeType is another alternative?

        H Offline
        H Offline
        honey the codewitch
        wrote on last edited by
        #6

        I have no idea what freetype is *googles* I don't need a C# wrapper. I can code in pretty much anything - taught myself some python last night because i needed some code from a script =). I just had never heard of freetype before. Thanks

        Real programmers use butterflies

        1 Reply Last reply
        0
        • H honey the codewitch

          That's neat, but they're just retro font files. I guess maybe some of the formats they have are easier to use than TTF but id I went that route I'd be forced to use say, .fon files or whatever, and I'd really like the end user of my library to be able to choose their own fonts. So .ttf is pretty much what's for dinner. I've got code to do the TTF rasterization now, I just need to modify it for my own nefarious purposes. It will be nice to have the drawing primitives of GFX sewn up, and this is the last of it, unless i decide to add things like bilinear resampling and antialiasing.

          Real programmers use butterflies

          R Offline
          R Offline
          Rick York
          wrote on last edited by
          #7

          Those are all pre-rasterized fonts. Yes, they are old but so what? For this purpose, that is exactly what I would use. This is for an Arduino right? Do you really want to pursue much beyond bitmap fonts? I certainly wouldn't. Anti-aliasing? Nope. I would not go beyond allowing the option for a transparent background or opaque. That is, for highest performance and that should be the highest priority in my opinion. If cosmetics are that high a priority then you are on the wrong platform as far as I am concerned.

          "They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"

          H 1 Reply Last reply
          0
          • R Rick York

            Those are all pre-rasterized fonts. Yes, they are old but so what? For this purpose, that is exactly what I would use. This is for an Arduino right? Do you really want to pursue much beyond bitmap fonts? I certainly wouldn't. Anti-aliasing? Nope. I would not go beyond allowing the option for a transparent background or opaque. That is, for highest performance and that should be the highest priority in my opinion. If cosmetics are that high a priority then you are on the wrong platform as far as I am concerned.

            "They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"

            H Offline
            H Offline
            honey the codewitch
            wrote on last edited by
            #8

            I was intending to render to a monochrome bitmap. I did manage to get it to render without anti-aliasing, and with single-bit-per-pixel position. That was not the problem. I could render any monospace font regardless of whether or not it was BMP based. Because I was rendering the font, and saving the result of the render as a bitmap. The only problem I ran into - THE ONLY problem, was positioning. .NET has no facility to accurately position fonts to a pixel perfect grid. That's the only problem. And yes, cosmetics are an issue, because sometimes, I'm being called on to write professional looking software, and professional looking software shouldn't look like elephant crap, even on an embedded device. They aren't always an issue in all circumstances, but they are when it comes to larger font renderings. If I need anti-aliasing i can bump from monochrome to grayscale and then treat the grayscale like an inverted alpha channel The ESP32 can handle displaying a small rendering of Lucida Console (for example) or I wouldn't be doing this.

            Real programmers use butterflies

            R 1 Reply Last reply
            0
            • CPalliniC CPallini

              Quote:

              The thing is, the GDI+ code underneath is perfectly capable of doing this. They just didn't expose i

              Then write a C++ program using Winapi & GDI+. I experienced myself the problem you have with C# and found it quite annoying. Eventually I used a free tool (unfortunately I don't remember its name) to rasterize the fonts.

              "In testa che avete, Signor di Ceprano?" -- Rigoletto

              H Offline
              H Offline
              honey the codewitch
              wrote on last edited by
              #9

              Yeah, I want to go the free tool route if possible, or otherwise whip this up quick and dirty. I just need to make a tool that's not standalone - it's just meant as a utility to generate font files my code needs.

              Real programmers use butterflies

              1 Reply Last reply
              0
              • H honey the codewitch

                I was intending to render to a monochrome bitmap. I did manage to get it to render without anti-aliasing, and with single-bit-per-pixel position. That was not the problem. I could render any monospace font regardless of whether or not it was BMP based. Because I was rendering the font, and saving the result of the render as a bitmap. The only problem I ran into - THE ONLY problem, was positioning. .NET has no facility to accurately position fonts to a pixel perfect grid. That's the only problem. And yes, cosmetics are an issue, because sometimes, I'm being called on to write professional looking software, and professional looking software shouldn't look like elephant crap, even on an embedded device. They aren't always an issue in all circumstances, but they are when it comes to larger font renderings. If I need anti-aliasing i can bump from monochrome to grayscale and then treat the grayscale like an inverted alpha channel The ESP32 can handle displaying a small rendering of Lucida Console (for example) or I wouldn't be doing this.

                Real programmers use butterflies

                R Offline
                R Offline
                Rick York
                wrote on last edited by
                #10

                Cool. Best of luck with it.

                "They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"

                1 Reply Last reply
                0
                • H honey the codewitch

                  My little graphics library needs to do text, and I thought "hey, I'll whip up a C# app to rasterize monospaced fonts to a monochrome bitmap." Just add a reference to System.Drawing to a console app, and then create a Bitmap and draw to it right? Wrong. Even after you set all of the text rendering hints, and even using GraphicsPath.AddString() for more accuracy, you cannot turn off the padding around the fonts, nor get the font to a pixel perfect height at all sizes. The thing is, the GDI+ code underneath is perfectly capable of doing this. They just didn't expose it. The alternative is reinventing the entire elephanting wheel and rasterizing the fonts myself. I found an open source project (under Apache license unfortunately) that I can use to build my tool. Fortunately that tool isn't part of my GFX package itself - it's just a utility to make files that the GFX code can read. But this shouldn't be necessary. They actually have to parse the TTFs and draw them manually. X|

                  Real programmers use butterflies

                  G Offline
                  G Offline
                  Gary R Wheeler
                  wrote on last edited by
                  #11

                  If I may be of assistance: GetGlyphOutlineA function (wingdi.h) - Win32 apps | Microsoft Docs[^]

                  Software Zen: delete this;

                  H 1 Reply Last reply
                  0
                  • G Gary R Wheeler

                    If I may be of assistance: GetGlyphOutlineA function (wingdi.h) - Win32 apps | Microsoft Docs[^]

                    Software Zen: delete this;

                    H Offline
                    H Offline
                    honey the codewitch
                    wrote on last edited by
                    #12

                    I think that's what GraphicsPath.AddString() calls but I could be wrong. At any rate, I'll give it a shot down the road. I've decided to import .FON files for the time being. Thanks! I'll bear this in mind.

                    Real programmers use butterflies

                    G 1 Reply Last reply
                    0
                    • H honey the codewitch

                      My little graphics library needs to do text, and I thought "hey, I'll whip up a C# app to rasterize monospaced fonts to a monochrome bitmap." Just add a reference to System.Drawing to a console app, and then create a Bitmap and draw to it right? Wrong. Even after you set all of the text rendering hints, and even using GraphicsPath.AddString() for more accuracy, you cannot turn off the padding around the fonts, nor get the font to a pixel perfect height at all sizes. The thing is, the GDI+ code underneath is perfectly capable of doing this. They just didn't expose it. The alternative is reinventing the entire elephanting wheel and rasterizing the fonts myself. I found an open source project (under Apache license unfortunately) that I can use to build my tool. Fortunately that tool isn't part of my GFX package itself - it's just a utility to make files that the GFX code can read. But this shouldn't be necessary. They actually have to parse the TTFs and draw them manually. X|

                      Real programmers use butterflies

                      B Offline
                      B Offline
                      BillWoodruff
                      wrote on last edited by
                      #13

                      fwiw: I wonder if what you observe is the result of the quantizing/hinting of outline-based fonts for display/rasterization at different point sizes.

                      «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

                      H 1 Reply Last reply
                      0
                      • B BillWoodruff

                        fwiw: I wonder if what you observe is the result of the quantizing/hinting of outline-based fonts for display/rasterization at different point sizes.

                        «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

                        H Offline
                        H Offline
                        honey the codewitch
                        wrote on last edited by
                        #14

                        I thought about that, but it doesn't seem like it, because the padding is consistent (in terms of physical proportions) as you increase the size. There seems to be some internal box layout (similar to CSS margins/padding) but I can't control it. I could be wrong of course. Being on the outside looking in when it comes to the implementation of this there's always the possibility, but I'm more confident than not about this.

                        Real programmers use butterflies

                        1 Reply Last reply
                        0
                        • H honey the codewitch

                          I think that's what GraphicsPath.AddString() calls but I could be wrong. At any rate, I'll give it a shot down the road. I've decided to import .FON files for the time being. Thanks! I'll bear this in mind.

                          Real programmers use butterflies

                          G Offline
                          G Offline
                          Gary R Wheeler
                          wrote on last edited by
                          #15

                          We used it back in the day under Windows 3.1 to render TrueType fonts into bitmaps for use in our commercial ink-jet printers. There are other calls in that same area that give you character metrics and other useful information for your application.

                          Software Zen: delete this;

                          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