diff --git a/Core/Canvas/CharWidthData.cs b/Core/Canvas/CharWidthData.cs index def50c3..2114fc5 100644 --- a/Core/Canvas/CharWidthData.cs +++ b/Core/Canvas/CharWidthData.cs @@ -33,9 +33,9 @@ public static class CharWidthData public static readonly short HelveticaNormalEuroWidth = 744; /// - /// Character widths for Helvetica Normal (range 0x20 to 0x7e). + /// Character widths for Helvetica Normal (range 0x20 to 0x7f). /// - public static readonly short[] HelveticaNormal_20_7E = { + public static readonly short[] HelveticaNormal_20_7F = { 278, // 0x20 278, // 0x21 ! 355, // 0x22 " @@ -130,13 +130,14 @@ public static class CharWidthData 334, // 0x7B { 260, // 0x7C | 334, // 0x7D } - 584 // 0x7E ~ + 584, // 0x7E ~ + 0 // unused }; /// - /// Character widths for Helvetica Normal (range 0xa0 to 0x17f). + /// Character widths for Helvetica Normal (range 0xa0 to 0xff). /// - public static readonly short[] HelveticaNormal_A0_17F = { + public static readonly short[] HelveticaNormal_A0_FF = { 278, // 0xA0 non-breaking space 333, // 0xA1 ¡ 556, // 0xA2 ¢ @@ -233,6 +234,12 @@ public static class CharWidthData 500, // 0xFD ý 556, // 0xFE þ 500, // 0xFF ÿ + }; + + /// + /// Character widths for Helvetica Normal (range 0x0100 to 0x017f). + /// + public static readonly short[] HelveticaNormal_100_17F = { 667, // 0x100 Ā 556, // 0x101 ā 667, // 0x102 Ă @@ -389,9 +396,9 @@ public static class CharWidthData public static readonly short HelveticaBoldEuroWidth = 744; /// - /// Character widths for Helvetica Bold (range 0x20 to 0x7e). + /// Character widths for Helvetica Bold (range 0x20 to 0x7f). /// - public static readonly short[] HelveticaBold_20_7E = { + public static readonly short[] HelveticaBold_20_7F = { 278, // 0x20 333, // 0x21 ! 474, // 0x22 " @@ -486,13 +493,14 @@ public static class CharWidthData 389, // 0x7B { 280, // 0x7C | 389, // 0x7D } - 584 // 0x7E ~ + 584, // 0x7E ~ + 0 // unused }; /// - /// Character widths for Helvetica Bold (range 0xa0 to 0x17f). + /// Character widths for Helvetica Bold (range 0xa0 to 0xff). /// - public static readonly short[] HelveticaBold_A0_17F = { + public static readonly short[] HelveticaBold_A0_FF = { 278, // 0xA0 non-breaking space 333, // 0xA1 ¡ 556, // 0xA2 ¢ @@ -589,6 +597,12 @@ public static class CharWidthData 556, // 0xFD ý 611, // 0xFE þ 556, // 0xFF ÿ + }; + + /// + /// Character widths for Helvetica Bold (range 0x0100 to 0x017f). + /// + public static readonly short[] HelveticaBold_100_17F = { 722, // 0x100 Ā 556, // 0x101 ā 722, // 0x102 Ă @@ -745,9 +759,9 @@ public static class CharWidthData public static readonly short ArialNormalEuroWidth = 556; /// - /// Character widths for Arial Normal (range 0x20 to 0x7e). + /// Character widths for Arial Normal (range 0x20 to 0x7f). /// - public static readonly short[] ArialNormal_20_7E = { + public static readonly short[] ArialNormal_20_7F = { 278, // 0x20 278, // 0x21 ! 355, // 0x22 " @@ -842,13 +856,14 @@ public static class CharWidthData 334, // 0x7B { 260, // 0x7C | 334, // 0x7D } - 584 // 0x7E ~ + 584, // 0x7E ~ + 0 // unused }; /// - /// Character widths for Arial Normal (range 0xa0 to 0x17f). + /// Character widths for Arial Normal (range 0xa0 to 0xff). /// - public static readonly short[] ArialNormal_A0_17F = { + public static readonly short[] ArialNormal_A0_FF = { 278, // 0xA0 non-breaking space 333, // 0xA1 ¡ 556, // 0xA2 ¢ @@ -945,6 +960,12 @@ public static class CharWidthData 500, // 0xFD ý 556, // 0xFE þ 500, // 0xFF ÿ + }; + + /// + /// Character widths for Arial Normal (range 0x0100 to 0x017f). + /// + public static readonly short[] ArialNormal_100_17F = { 667, // 0x100 Ā 556, // 0x101 ā 667, // 0x102 Ă @@ -1101,9 +1122,9 @@ public static class CharWidthData public static readonly short ArialBoldEuroWidth = 556; /// - /// Character widths for Arial Bold (range 0x20 to 0x7e). + /// Character widths for Arial Bold (range 0x20 to 0x7f). /// - public static readonly short[] ArialBold_20_7E = { + public static readonly short[] ArialBold_20_7F = { 278, // 0x20 333, // 0x21 ! 474, // 0x22 " @@ -1198,13 +1219,14 @@ public static class CharWidthData 389, // 0x7B { 280, // 0x7C | 389, // 0x7D } - 584 // 0x7E ~ + 584, // 0x7E ~ + 0 // unused }; /// - /// Character widths for Arial Bold (range 0xa0 to 0x17f). + /// Character widths for Arial Bold (range 0xa0 to 0xff). /// - public static readonly short[] ArialBold_A0_17F = { + public static readonly short[] ArialBold_A0_FF = { 278, // 0xA0 non-breaking space 333, // 0xA1 ¡ 556, // 0xA2 ¢ @@ -1301,6 +1323,12 @@ public static class CharWidthData 556, // 0xFD ý 611, // 0xFE þ 556, // 0xFF ÿ + }; + + /// + /// Character widths for Arial Bold (range 0x0100 to 0x017f). + /// + public static readonly short[] ArialBold_100_17F = { 722, // 0x100 Ā 556, // 0x101 ā 722, // 0x102 Ă @@ -1457,9 +1485,9 @@ public static class CharWidthData public static readonly short LiberationSansNormalEuroWidth = 556; /// - /// Character widths for Liberation Sans Normal (range 0x20 to 0x7e). + /// Character widths for Liberation Sans Normal (range 0x20 to 0x7f). /// - public static readonly short[] LiberationSansNormal_20_7E = { + public static readonly short[] LiberationSansNormal_20_7F = { 278, // 0x20 278, // 0x21 ! 355, // 0x22 " @@ -1554,13 +1582,14 @@ public static class CharWidthData 334, // 0x7B { 260, // 0x7C | 334, // 0x7D } - 584 // 0x7E ~ + 584, // 0x7E ~ + 0 // unused }; /// - /// Character widths for Liberation Sans Normal (range 0xa0 to 0x17f). + /// Character widths for Liberation Sans Normal (range 0xa0 to 0xff). /// - public static readonly short[] LiberationSansNormal_A0_17F = { + public static readonly short[] LiberationSansNormal_A0_FF = { 278, // 0xA0 non-breaking space 333, // 0xA1 ¡ 556, // 0xA2 ¢ @@ -1657,6 +1686,13 @@ public static class CharWidthData 500, // 0xFD ý 556, // 0xFE þ 500, // 0xFF ÿ + }; + + /// + /// Character widths for Liberation Sans Normal (range 0x0100 to 0x017f). + /// + public static readonly short[] LiberationSansNormal_100_17F = { + 667, // 0x100 Ā 556, // 0x101 ā 667, // 0x102 Ă @@ -1813,9 +1849,9 @@ public static class CharWidthData public static readonly short LiberationSansBoldEuroWidth = 556; /// - /// Character widths for Liberation Sans Bold (range 0x20 to 0x7e). + /// Character widths for Liberation Sans Bold (range 0x20 to 0x7f). /// - public static readonly short[] LiberationSansBold_20_7E = { + public static readonly short[] LiberationSansBold_20_7F = { 278, // 0x20 333, // 0x21 ! 474, // 0x22 " @@ -1910,13 +1946,14 @@ public static class CharWidthData 389, // 0x7B { 280, // 0x7C | 389, // 0x7D } - 584 // 0x7E ~ + 584, // 0x7E ~ + 0 // unused }; /// - /// Character widths for Liberation Sans Bold (range 0xa0 to 0x17f). + /// Character widths for Liberation Sans Bold (range 0xa0 to 0xff). /// - public static readonly short[] LiberationSansBold_A0_17F = { + public static readonly short[] LiberationSansBold_A0_FF = { 278, // 0xA0 non-breaking space 333, // 0xA1 ¡ 556, // 0xA2 ¢ @@ -2013,6 +2050,13 @@ public static class CharWidthData 556, // 0xFD ý 611, // 0xFE þ 556, // 0xFF ÿ + }; + + + /// + /// Character widths for Liberation Sans Bold (range 0x0100 to 0x017f). + /// + public static readonly short[] LiberationSansBold_100_17F = { 722, // 0x100 Ā 556, // 0x101 ā 722, // 0x102 Ă @@ -2169,9 +2213,9 @@ public static class CharWidthData public static readonly short FrutigerNormalEuroWidth = 556; /// - /// Character widths for Frutiger Normal (range 0x20 to 0x7e). + /// Character widths for Frutiger Normal (range 0x20 to 0x7f). /// - public static readonly short[] FrutigerNormal_20_7E = { + public static readonly short[] FrutigerNormal_20_7F = { 278, // 0x20 389, // 0x21 ! 556, // 0x22 " @@ -2266,13 +2310,14 @@ public static class CharWidthData 278, // 0x7B { 222, // 0x7C | 278, // 0x7D } - 600 // 0x7E ~ + 600, // 0x7E ~ + 0 // unused }; /// - /// Character widths for Frutiger Normal (range 0xa0 to 0x17f). + /// Character widths for Frutiger Normal (range 0xa0 to 0xff). /// - public static readonly short[] FrutigerNormal_A0_17F = { + public static readonly short[] FrutigerNormal_A0_FF = { 278, // 0xA0 non-breaking space 389, // 0xA1 ¡ 556, // 0xA2 ¢ @@ -2369,6 +2414,13 @@ public static class CharWidthData 444, // 0xFD ý 556, // 0xFE þ 444, // 0xFF ÿ + }; + + + /// + /// Character widths for Frutiger Normal (range 0x0100 to 0x017f). + /// + public static readonly short[] FrutigerNormal_100_17F = { 667, // 0x100 Ā 500, // 0x101 ā 667, // 0x102 Ă @@ -2525,9 +2577,9 @@ public static class CharWidthData public static readonly short FrutigerBoldEuroWidth = 556; /// - /// Character widths for Frutiger Bold (range 0x20 to 0x7e). + /// Character widths for Frutiger Bold (range 0x20 to 0x7f). /// - public static readonly short[] FrutigerBold_20_7E = { + public static readonly short[] FrutigerBold_20_7F = { 278, // 0x20 389, // 0x21 ! 481, // 0x22 " @@ -2622,13 +2674,14 @@ public static class CharWidthData 333, // 0x7B { 222, // 0x7C | 333, // 0x7D } - 600 // 0x7E ~ + 600, // 0x7E ~ + 0 // unused }; /// - /// Character widths for Frutiger Bold (range 0xa0 to 0x17f). + /// Character widths for Frutiger Bold (range 0xa0 to 0xff). /// - public static readonly short[] FrutigerBold_A0_17F = { + public static readonly short[] FrutigerBold_A0_FF = { 278, // 0xA0 non-breaking space 389, // 0xA1 ¡ 556, // 0xA2 ¢ @@ -2725,6 +2778,12 @@ public static class CharWidthData 556, // 0xFD ý 611, // 0xFE þ 556, // 0xFF ÿ + }; + + /// + /// Character widths for Frutiger Bold (range 0x0100 to 0x017f). + /// + public static readonly short[] FrutigerBold_100_17F = { 722, // 0x100 Ā 556, // 0x101 ā 722, // 0x102 Ă diff --git a/Core/Canvas/FontMetrics.cs b/Core/Canvas/FontMetrics.cs index 6b68749..3776548 100644 --- a/Core/Canvas/FontMetrics.cs +++ b/Core/Canvas/FontMetrics.cs @@ -17,8 +17,9 @@ public class FontMetrics { private const double PtToMm = 25.4 / 72; - private readonly short[] _charWidthx20x7E; - private readonly short[] _charWidthxA0x17F; + private readonly short[] _charWidthx20x7F; + private readonly short[] _charWidthxA0xFF; + private readonly short[] _charWidthx100x17F; private readonly short[] _charWidthx218x21B; private readonly short _charDefaultWidth; private readonly short _charNDashWidth; @@ -38,8 +39,9 @@ public FontMetrics(string fontFamilyList) FirstFontFamily = GetFirstFontFamily(fontFamilyList); var family = FirstFontFamily.ToLowerInvariant(); - short[] boldCharWidthx20x7E; - short[] boldCharWidthxA0x17F; + short[] boldCharWidthx20x7F; + short[] boldCharWidthxA0xFF; + short[] boldCharWidthx100x17F; short[] boldCharWidthx218x21B; short boldCharDefaultWidth; short boldCharNDashWidth; @@ -47,14 +49,16 @@ public FontMetrics(string fontFamilyList) if (family.Contains("arial")) { - _charWidthx20x7E = CharWidthData.ArialNormal_20_7E; - _charWidthxA0x17F = CharWidthData.ArialNormal_A0_17F; + _charWidthx20x7F = CharWidthData.ArialNormal_20_7F; + _charWidthxA0xFF = CharWidthData.ArialNormal_A0_FF; + _charWidthx100x17F = CharWidthData.ArialNormal_100_17F; _charWidthx218x21B = CharWidthData.ArialNormal_218_21B; _charDefaultWidth = CharWidthData.ArialNormalDefaultWidth; _charNDashWidth = CharWidthData.ArialNormalNDashWidth; _charEuroWidth = CharWidthData.ArialNormalEuroWidth; - boldCharWidthx20x7E = CharWidthData.ArialBold_20_7E; - boldCharWidthxA0x17F = CharWidthData.ArialBold_A0_17F; + boldCharWidthx20x7F = CharWidthData.ArialBold_20_7F; + boldCharWidthxA0xFF = CharWidthData.ArialBold_A0_FF; + boldCharWidthx100x17F = CharWidthData.ArialBold_100_17F; boldCharWidthx218x21B = CharWidthData.ArialBold_218_21B; boldCharDefaultWidth = CharWidthData.ArialBoldDefaultWidth; boldCharNDashWidth = CharWidthData.ArialBoldNDashWidth; @@ -62,14 +66,16 @@ public FontMetrics(string fontFamilyList) } else if (family.Contains("liberation") && family.Contains("sans")) { - _charWidthx20x7E = CharWidthData.LiberationSansNormal_20_7E; - _charWidthxA0x17F = CharWidthData.LiberationSansNormal_A0_17F; + _charWidthx20x7F = CharWidthData.LiberationSansNormal_20_7F; + _charWidthxA0xFF = CharWidthData.LiberationSansNormal_A0_FF; + _charWidthx100x17F = CharWidthData.LiberationSansNormal_100_17F; _charWidthx218x21B = CharWidthData.LiberationSansNormal_218_21B; _charDefaultWidth = CharWidthData.LiberationSansNormalDefaultWidth; _charNDashWidth = CharWidthData.LiberationSansNormalNDashWidth; _charEuroWidth = CharWidthData.LiberationSansNormalEuroWidth; - boldCharWidthx20x7E = CharWidthData.LiberationSansBold_20_7E; - boldCharWidthxA0x17F = CharWidthData.LiberationSansBold_A0_17F; + boldCharWidthx20x7F = CharWidthData.LiberationSansBold_20_7F; + boldCharWidthxA0xFF = CharWidthData.LiberationSansBold_A0_FF; + boldCharWidthx100x17F = CharWidthData.LiberationSansBold_100_17F; boldCharWidthx218x21B = CharWidthData.LiberationSansBold_218_21B; boldCharDefaultWidth = CharWidthData.LiberationSansBoldDefaultWidth; boldCharNDashWidth = CharWidthData.LiberationSansBoldNDashWidth; @@ -77,14 +83,16 @@ public FontMetrics(string fontFamilyList) } else if (family.Contains("frutiger")) { - _charWidthx20x7E = CharWidthData.FrutigerNormal_20_7E; - _charWidthxA0x17F = CharWidthData.FrutigerNormal_A0_17F; + _charWidthx20x7F = CharWidthData.FrutigerNormal_20_7F; + _charWidthxA0xFF = CharWidthData.FrutigerNormal_A0_FF; + _charWidthx100x17F = CharWidthData.FrutigerNormal_100_17F; _charWidthx218x21B = CharWidthData.FrutigerNormal_218_21B; _charDefaultWidth = CharWidthData.FrutigerNormalDefaultWidth; _charNDashWidth = CharWidthData.FrutigerNormalNDashWidth; _charEuroWidth = CharWidthData.FrutigerNormalEuroWidth; - boldCharWidthx20x7E = CharWidthData.FrutigerBold_20_7E; - boldCharWidthxA0x17F = CharWidthData.FrutigerBold_A0_17F; + boldCharWidthx20x7F = CharWidthData.FrutigerBold_20_7F; + boldCharWidthxA0xFF = CharWidthData.FrutigerBold_A0_FF; + boldCharWidthx100x17F = CharWidthData.FrutigerBold_100_17F; boldCharWidthx218x21B = CharWidthData.FrutigerBold_218_21B; boldCharDefaultWidth = CharWidthData.FrutigerBoldDefaultWidth; boldCharNDashWidth = CharWidthData.FrutigerBoldNDashWidth; @@ -92,29 +100,32 @@ public FontMetrics(string fontFamilyList) } else { - _charWidthx20x7E = CharWidthData.HelveticaNormal_20_7E; - _charWidthxA0x17F = CharWidthData.HelveticaNormal_A0_17F; + _charWidthx20x7F = CharWidthData.HelveticaNormal_20_7F; + _charWidthxA0xFF = CharWidthData.HelveticaNormal_A0_FF; + _charWidthx100x17F = CharWidthData.HelveticaNormal_100_17F; _charWidthx218x21B = CharWidthData.HelveticaNormal_218_21B; _charDefaultWidth = CharWidthData.HelveticaNormalDefaultWidth; _charNDashWidth = CharWidthData.HelveticaNormalNDashWidth; _charEuroWidth = CharWidthData.HelveticaNormalEuroWidth; - boldCharWidthx20x7E = CharWidthData.HelveticaBold_20_7E; - boldCharWidthxA0x17F = CharWidthData.HelveticaBold_A0_17F; + boldCharWidthx20x7F = CharWidthData.HelveticaBold_20_7F; + boldCharWidthxA0xFF = CharWidthData.HelveticaBold_A0_FF; + boldCharWidthx100x17F = CharWidthData.HelveticaBold_100_17F; boldCharWidthx218x21B = CharWidthData.HelveticaBold_218_21B; boldCharDefaultWidth = CharWidthData.HelveticaBoldDefaultWidth; boldCharNDashWidth = CharWidthData.HelveticaBoldNDashWidth; boldCharEuroWidth = CharWidthData.HelveticaBoldEuroWidth; } - _boldMetrics = new FontMetrics(boldCharWidthx20x7E, boldCharWidthxA0x17F, boldCharWidthx218x21B, boldCharDefaultWidth, boldCharNDashWidth, boldCharEuroWidth); + _boldMetrics = new FontMetrics(boldCharWidthx20x7F, boldCharWidthxA0xFF, boldCharWidthx100x17F, boldCharWidthx218x21B, boldCharDefaultWidth, boldCharNDashWidth, boldCharEuroWidth); } - private FontMetrics(short[] charWidthx20x7E, short[] charWidthxA0x17F, short[] charWidthx218x21B, short charDefaultWidth, short charNDashWidth, short charEuroWidth) + private FontMetrics(short[] charWidthx20x7F, short[] charWidthxA0xFF, short[] charWidthx100x17F, short[] charWidthx218x21B, short charDefaultWidth, short charNDashWidth, short charEuroWidth) { FontFamilyList = null; FirstFontFamily = null; - _charWidthx20x7E = charWidthx20x7E; - _charWidthxA0x17F = charWidthxA0x17F; + _charWidthx20x7F = charWidthx20x7F; + _charWidthxA0xFF = charWidthxA0xFF; + _charWidthx100x17F = charWidthx100x17F; _charWidthx218x21B = charWidthx218x21B; _charDefaultWidth = charDefaultWidth; _charNDashWidth = charNDashWidth; @@ -349,13 +360,17 @@ public double TextWidth(string text, int fontSize, bool isBold) private short CharWidth(char ch) { short width = 0; - if (ch >= 0x20 && ch <= 0x7e) + if (ch >= 0x20 && ch <= 0x7f) { - width = _charWidthx20x7E[ch - 0x20]; + width = _charWidthx20x7F[ch - 0x20]; } - else if (ch >= 0xa0 && ch <= 0x17f) + else if (ch >= 0xa0 && ch <= 0xff) { - width = _charWidthxA0x17F[ch - 0xa0]; + width = _charWidthxA0xFF[ch - 0xa0]; + } + else if (ch >= 0x100 && ch <= 0x17f) + { + width = _charWidthx100x17F[ch - 0x100]; } else if (ch >= 0x0218 && ch <= 0x021b) {