//// This code is part of Document Solutions for Imaging demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.IO;usingSystem.Drawing;usingGrapeCity.Documents.Imaging;usingGrapeCity.Documents.Text;usingGCTEXT = GrapeCity.Documents.Text; namespaceDsImagingWeb.Demos{// This sample demonstrates how to use TrueType font hinting instructions.//// Many TrueType fonts include low-level hinting instructions.// The original purpose of introducing hinting instructions was // to improve the look of glyphs when the font size is comparable// to the device resolution.// Such instructions are also used (especially in CJK fonts)// to reuse some glyph parts in different glyphs regardless of the font size.// GcGraphics supports hinting instructions. To enable it, set// TextFormat.EnableFontHinting property to true when rendering text.// // This sample renders a string using small sans-serif and serif fonts// with hinting turned OFF and ON.publicclassTrueTypeHinting {publicGcBitmapGenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null) {var bmp = newGcBitmap(pixelSize.Width, pixelSize.Height, true, dpi, dpi);var dy = dpi / 2;var ip = newPointF(dpi, dpi);using (var g = bmp.CreateGraphics(Color.White)) {// Turning anti-aliasing off makes the hinting effect on small text more obvious: g.Renderer.Aliased = true; var sOff = "Hinting OFF: ";var sOn = "Hinting ON: "; // Draw a string with hinting instructions off and on:var text = "The quick brown fox jumps over the lazy dog."; var tf = newTextFormat() {Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeSans.ttf")),FontSize = 12,EnableFontHinting = false }; g.DrawString(sOff + text, tf, ip); ip.Y += dy; tf.FontSize = 10; g.DrawString(sOff + text, tf, ip); ip.Y += dy * 2; tf.EnableFontHinting = true; tf.FontSize = 12; g.DrawString(sOn + text, tf, ip); ip.Y += dy; tf.FontSize = 10; g.DrawString(sOn + text, tf, ip); ip.Y += dy * 2; // Draw the same string with a serif font: tf.Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeSerif.ttf")); tf.EnableFontHinting = false; tf.FontSize = 12; g.DrawString(sOff + text, tf, ip); ip.Y += dy; tf.FontSize = 10; g.DrawString(sOff + text, tf, ip); ip.Y += dy * 2; tf.EnableFontHinting = true; tf.FontSize = 12; g.DrawString(sOn + text, tf, ip); ip.Y += dy; tf.FontSize = 10; g.DrawString(sOn + text, tf, ip); ip.Y += dy * 2; }// Done:return bmp; } }}