static void RenderSvgSample(string text, int size, PointF origin, Gdi32Font font, StringBuilder htmlBuilder) { htmlBuilder.AppendLine(@$ "<svg style=" "border: solid black" " width=" "10em" " height=" "10em" " viewBox=" "0 0 {size} {size}" ">"); var outline = font.GetOutline(text, OutlineMode.Native); if (outline is { })
static void Main(string[] args) { var size = 512; var origin = PointF.Empty; using (var ipaFont = new Gdi32Font("IPAmj明朝", FontSizeUnit.Pixel, size, FontWeightConsts.FW_NORMAL, false, false, false, 1, Gdi32FontQuality.Default)) using (var msMinchoFont = new Gdi32Font("MS 明朝", FontSizeUnit.Pixel, size, FontWeightConsts.FW_NORMAL, false, false, false, 1, Gdi32FontQuality.Default)) using (var meiryoFont = new Gdi32Font("Meiryo UI", FontSizeUnit.Pixel, size, FontWeightConsts.FW_NORMAL, false, false, false, 1, Gdi32FontQuality.Default)) using (var arialFont = new Gdi32Font("Arial", FontSizeUnit.Pixel, size, FontWeightConsts.FW_NORMAL, false, false, false, 1, Gdi32FontQuality.Default)) using (var gothicFont = new Gdi32Font("MS UI Gothic", FontSizeUnit.Pixel, size, FontWeightConsts.FW_NORMAL, false, false, false, 1, Gdi32FontQuality.Default)) { var htmlBuilder = new StringBuilder(4096); htmlBuilder.AppendLine("<html><body>"); htmlBuilder.AppendLine("<h1>SVGTest</h1>"); htmlBuilder.AppendLine("<h2>IPAmj明朝</h2>"); RenderSvgSample("f", size, origin, ipaFont, htmlBuilder); RenderSvgSample("g", size, origin, ipaFont, htmlBuilder); RenderSvgSample("薔", size, origin, ipaFont, htmlBuilder); RenderSvgSample("■", size, origin, ipaFont, htmlBuilder); htmlBuilder.AppendLine("<h2>MS 明朝</h2>"); RenderSvgSample("f", size, origin, msMinchoFont, htmlBuilder); RenderSvgSample("g", size, origin, msMinchoFont, htmlBuilder); RenderSvgSample("薔", size, origin, msMinchoFont, htmlBuilder); RenderSvgSample("■", size, origin, msMinchoFont, htmlBuilder); htmlBuilder.AppendLine("<h2>Meiryo UI</h2>"); RenderSvgSample("f", size, origin, meiryoFont, htmlBuilder); RenderSvgSample("g", size, origin, meiryoFont, htmlBuilder); RenderSvgSample("薔", size, origin, meiryoFont, htmlBuilder); RenderSvgSample("■", size, origin, meiryoFont, htmlBuilder); htmlBuilder.AppendLine("<h2>MS UI Gothic</h2>"); RenderSvgSample("f", size, origin, gothicFont, htmlBuilder); RenderSvgSample("g", size, origin, gothicFont, htmlBuilder); RenderSvgSample("薔", size, origin, gothicFont, htmlBuilder); RenderSvgSample("■", size, origin, gothicFont, htmlBuilder); htmlBuilder.AppendLine("<h2>Arial</h2>"); RenderSvgSample("f", size, origin, arialFont, htmlBuilder); RenderSvgSample("g", size, origin, arialFont, htmlBuilder); htmlBuilder.AppendLine("<h2>比較</h2>"); RenderSvgSample("薔", size, origin, msMinchoFont, htmlBuilder); RenderSvgSample("薔", size, origin, meiryoFont, htmlBuilder); htmlBuilder.AppendLine("</body></html>"); File.WriteAllText("test.html", htmlBuilder.ToString(), Encoding.UTF8); var info = new ProcessStartInfo { FileName = "test.html", UseShellExecute = true, }; Process.Start(info); }
public static void SetCharFormatFont(this RichTextBox richTextBox, bool selectionOnly, Gdi32Font font) { IntPtr handle = richTextBox.Handle; if (handle == IntPtr.Zero) { throw new InvalidOperationException(); } int dwMask = -1476394993; int num = 0; if (font.Bold != BooleanConsts.FALSE) { num |= CFM_BOLD; } if (font.Italic != BooleanConsts.FALSE) { num |= CFM_ITALIC; } if (font.Underline != BooleanConsts.FALSE) { num |= CFM_UNDERLINE; } if (font.Strikeout != BooleanConsts.FALSE) { num |= CFM_STRIKEOUT; } byte[] bytes; if (Marshal.SystemDefaultCharSize == 1) { throw new PlatformNotSupportedException(); } bytes = Encoding.Unicode.GetBytes(font.Logfont.lfFaceName); CHARFORMATW cHARFORMATW = new CHARFORMATW(); for (int j = 0; j < bytes.Length; j++) { cHARFORMATW.szFaceName[j] = bytes[j]; } cHARFORMATW.dwMask = dwMask; cHARFORMATW.dwEffects = num; cHARFORMATW.yHeight = (int)(font.SizeInPoints * 20f); cHARFORMATW.bCharSet = font.Logfont.lfCharSet; cHARFORMATW.bPitchAndFamily = font.Logfont.lfPitchAndFamily; SendMessage(new HandleRef(richTextBox, handle), EM_SETCHARFORMAT, selectionOnly ? SCF_SELECTION : SCF_ALL, cHARFORMATW); }