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#
  4. GDI+ Problem

GDI+ Problem

Scheduled Pinned Locked Moved C#
graphicsquestionwinformshelp
6 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.
  • O Offline
    O Offline
    occcy
    wrote on last edited by
    #1

    Hello! GDI+ text output makes me sick :doh: Sometimes GDI+ writes text with wide s p a c e s between letters, sometimes it writes letters very close together....The same with words...:eek: How can I configure the text drawing style or how can I solve this problems? My actual code for text output: StringFormat Format=new StringFormat(); Format.FormatFlags=   StringFormatFlags.NoWrap | StringFormatFlags.NoFontFallback |   StringFormatFlags.LineLimit | StringFormatFlags.MeasureTrailingSpaces; G.DrawString("Some text",Font,Brush,0,0,Format); //or, after measuring the string: G.DrawString("Some text",Font,Brush,TextRect,Format);

    B H L 3 Replies Last reply
    0
    • O occcy

      Hello! GDI+ text output makes me sick :doh: Sometimes GDI+ writes text with wide s p a c e s between letters, sometimes it writes letters very close together....The same with words...:eek: How can I configure the text drawing style or how can I solve this problems? My actual code for text output: StringFormat Format=new StringFormat(); Format.FormatFlags=   StringFormatFlags.NoWrap | StringFormatFlags.NoFontFallback |   StringFormatFlags.LineLimit | StringFormatFlags.MeasureTrailingSpaces; G.DrawString("Some text",Font,Brush,0,0,Format); //or, after measuring the string: G.DrawString("Some text",Font,Brush,TextRect,Format);

      B Offline
      B Offline
      Broken God
      wrote on last edited by
      #2

      Does this all happen with the same font?

      O 1 Reply Last reply
      0
      • B Broken God

        Does this all happen with the same font?

        O Offline
        O Offline
        occcy
        wrote on last edited by
        #3

        Yes, it does!

        H 1 Reply Last reply
        0
        • O occcy

          Yes, it does!

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          Try a different font to determine if the font is causing the problem.

          -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

          1 Reply Last reply
          0
          • O occcy

            Hello! GDI+ text output makes me sick :doh: Sometimes GDI+ writes text with wide s p a c e s between letters, sometimes it writes letters very close together....The same with words...:eek: How can I configure the text drawing style or how can I solve this problems? My actual code for text output: StringFormat Format=new StringFormat(); Format.FormatFlags=   StringFormatFlags.NoWrap | StringFormatFlags.NoFontFallback |   StringFormatFlags.LineLimit | StringFormatFlags.MeasureTrailingSpaces; G.DrawString("Some text",Font,Brush,0,0,Format); //or, after measuring the string: G.DrawString("Some text",Font,Brush,TextRect,Format);

            H Offline
            H Offline
            Heath Stewart
            wrote on last edited by
            #5

            There was a discussion not long ago about GDI+ squishing characters together at the end of a sentance when NoWrap was used (or a couple other conditions were true). This lead to a topic on MSDN about why it does that and the proper StringFormat to use to eliminate that (StringFormat.GenericTypographic). Try to use the same flags as that if possible. As far as spaces appearing between letters, this is fairly odd. I've never seen this when drawing my own strings and have never seen anything documented to even control this. Either the text you're passing has spaces (inproper Unicode string?) or the font you're using has some issues. Try a different one and see.

            -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

            1 Reply Last reply
            0
            • O occcy

              Hello! GDI+ text output makes me sick :doh: Sometimes GDI+ writes text with wide s p a c e s between letters, sometimes it writes letters very close together....The same with words...:eek: How can I configure the text drawing style or how can I solve this problems? My actual code for text output: StringFormat Format=new StringFormat(); Format.FormatFlags=   StringFormatFlags.NoWrap | StringFormatFlags.NoFontFallback |   StringFormatFlags.LineLimit | StringFormatFlags.MeasureTrailingSpaces; G.DrawString("Some text",Font,Brush,0,0,Format); //or, after measuring the string: G.DrawString("Some text",Font,Brush,TextRect,Format);

              L Offline
              L Offline
              leppie
              wrote on last edited by
              #6

              This is a known problem in GDI+. The resolution is to use non-gridfit font hinting or a monospaced font. You should also use FitBlackBox to prevent the lines from painted at slighty different heights. Here's how you can check for it (note: i have a fonthint field in my class): Also AA fonts look very poor in small sizes.

              void CheckFontBug(Graphics g)
              {
              //is font monospace?
              float w = g.MeasureString("w", font, int.MaxValue, sf).Width * 10f;
              float l = g.MeasureString("llllllllll", font, int.MaxValue, sf).Width;
              fonthint = (System.Math.Abs(w-l) > 0.005f) ? //allow float error
              (fontheight > 14f ? TextRenderingHint.AntiAlias : TextRenderingHint.SingleBitPerPixel) :
              TextRenderingHint.SystemDefault;
              }

              leppie::AllocCPArticle("Zee blog");
              Seen on my Campus BBS: Linux is free...coz no-one wants to pay for 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