.net - Strange exception "does not support style 'regular'" on GDI+ -


I'm running a test about fonts on Windows8.1 x64. Using NET Framework 4.0 Then the problem arises ...

After installing 1000-1500 fonts in the system, I try to get all the fonts using the following code and test my render size.

  static void test3 () {var bitmap = new System.Drawing.Bitmap (500, 500, System.Drawing.Imaging.PixelFormat.Format32bppArgb) ; Var g = System.Drawing.Graphics.FromImage (bitmap); Forchha (Family Family in FanFamily) {Try {console.light ("test [" + F. name + "] ..."); Var fn = new system Drawing Font (f, 16.0 f, system. Drawing.fontcetyl .regular); G.MeasureString ("test test æμ ?? e ?? æμ ?? e ?? æŬà© · æ · à© · ç¹ ?? é« ?? ° C ¡é «?? æ ¥ · is« ?? ç¹ ?? ½ half ?? ç®? ½ ¥ ¥ · ä½ ?? ", fn); Console.WriteLine ("[OK]"); } Catch (Exception Pre) {Console.WriteLine ("[ERR]" + pre-message); }}}   

But unfortunately, this piece of code can not run normally, so many types of ERR will appear:

 show error

Notice the row with the red border It is said that 'A' is the font ?? Half ?? '

  static void test2 () {var bitmap = new system.Drawing.Bitmap (500, 500, System.Documentation.imaging.pixel format.format 32bparbb); Var g = System.Drawing.Graphics.FromImage (bitmap); Four F. in Fourfamily Filiali (Where s = & gt; s.Name == "é» ?? half a ?? ")) {{console.write (" test ["+ f.Name +"] .. "); Var fn = new system Drawing Font (f, 16.0 f, system. Drawing.fontcetyl .regular); G.MeasureString ("test test æμ ?? e ?? æμ ?? e ?? æŬà© · æ · à© · ç¹ ?? é« ?? ° C ¡é «?? æ ¥ · is« ?? ç¹ ?? ½ half ?? ç®? ½ ¥ ¥ · ä½ ?? ", fn); Console.WriteLine ("[OK]"); } Catch (Exception Pre) {Console.WriteLine ("[ERR]" + pre-message); }}}   

This just ignores all other fonts, but only 'A' »'A half'? 'And here's the result:

....

. ... and now I'm totally confused. Can anyone explain why? Thank you.

[UPDATED] Here's More Checks

Consider these code snippets:

[Code1]

  var Bitmap = new system Drawing. Bitmap (500, 500, system. Drawing imaging. Pixel format.format 32bparbb); Var g = System.Drawing.Graphics.FromImage (bitmap); Var fam = fontfamily family; Var dic1 = fam.ToDictionary (s = & gt; s.Name, s => s.IsStyle available (font style regular)); Console.posted line (DIC 1. value number (s => gt; s)); Bitmap = new System.Drawing.Bitmap (500, 500, System.Drawing.Imaging.PixelFormat.Format32bppArgb) on the   

[code2]

 ; Var g = System.Drawing.Graphics.FromImage (bitmap); Var fam = fontfamily family; On top = dic2 = fam.ToDictionary (s =>, s = n, s => {var b = s.IsStyleAvailable (FontStyle.Regular); if (b) {var fn = new System.Drawing.Font , 16.0 f, System.Drawing.FontStyle.Regular); try {g.MeasureString (s.Name, fn);} Catch (Exception Pre) {Console.WriteLine (s.Name + "-> Failure -> ; "+ Previous message);} fn.Dispose ();} else {Console.WriteLine (s.Name +" - & gt; not support. ");} Return b;}); Console.Protected Line (Dye 2. Value Number (S => S));   

They are both for calculating regular supported fonts. The only difference was in the second code snippet, we use MesureString to test a string if it supports regularly.

But to run them specifically, you will actually see the result differently ....

 two results

(Note that the second code of the result was from 1)

Then I really want to ask: Why do some fonts Regularly reported in Code 1, but do not support regularly in Code 2? ...

Did the same font work before? I remember that something was going on in some familiarity and the exception was thrown because the fonts did not support the specific style. You can read, it tells your problem in more technologically.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -