/// <summary> /// Creates a <see cref="GdiFontMetrics"/> object from <b>baseFontName</b> /// </summary> private void ObtainFontMetrics() { dc = new GdiDeviceContent(); GdiFont font = GdiFont.CreateDesignFont( properties.FaceName, properties.IsBold, properties.IsItalic, dc); unicodeRanges = new GdiUnicodeRanges(dc); metrics = font.GetMetrics(dc); }
public GdiFontCreator(GdiDeviceContent dc) { this.dc = dc; this.header = new TrueTypeHeader(); this.ms = new MemoryStream(); this.fs = new FontFileStream(ms); }
internal GdiFontMetrics(GdiDeviceContent dc, GdiFont currentFont) { if (dc.Handle == IntPtr.Zero) { throw new ArgumentNullException("dc", "Handle to device context cannot be null"); } if (dc.GetCurrentObject(GdiDcObject.Font) == IntPtr.Zero) { throw new ArgumentException("dc", "No font selected into supplied device context"); } this.dc = dc; this.currentFont = currentFont; // FontFileReader requires the font facename because the font may exist in // a TrueType collection. StringBuilder builder = new StringBuilder(255); LibWrapper.GetTextFace(dc.Handle, builder.Capacity, builder); faceName = builder.ToString(); ranges = new GdiUnicodeRanges(dc); reader = new FontFileReader(new MemoryStream(GetFontData()), faceName); converter = new PdfUnitConverter(EmSquare); // After we have cached the font data, we can safely delete the resource currentFont.Dispose(); }
/// <summary> /// Class constructor. /// </summary> /// <param name="start">Value representing start of unicode range.</param> /// <param name="end">Value representing end of unicode range.</param> public UnicodeRange(GdiDeviceContent dc, ushort start, ushort end) { if (start > end) { throw new ArgumentException("start cannot be greater than end"); } this.dc = dc; this.start = start; this.end = end; }
/// <summary> /// Creates a font whose height is equal to the negative value /// of the EM Square /// </summary> /// <param name="faceName">The typeface name of a font.</param> /// <returns></returns> public static GdiFont CreateDesignFont(string faceName, bool bold, bool italic, GdiDeviceContent dc) { // TODO: Is there a simpler method of obtaining the em-sqaure? GdiFont tempFont = GdiFont.CreateFont(faceName, 2048, bold, italic); dc.SelectFont(tempFont); GdiFontMetrics metrics = tempFont.GetMetrics(dc); tempFont.Dispose(); return CreateFont(faceName, -Math.Abs(metrics.EmSquare), bold, italic); }
/// <summary> /// Loads all the unicode ranges. /// </summary> private void LoadRanges(GdiDeviceContent dc) { GlyphSet glyphSet = new GlyphSet(); uint size = LibWrapper.GetFontUnicodeRanges(dc.Handle, glyphSet); if (size == 0) { throw new Exception("Unable to retrieve unicode ranges."); } unicodeRanges = new UnicodeRange[glyphSet.cRanges]; for (int i = 0, offset = 0; i < glyphSet.cRanges; i++) { ushort wcLow = (ushort) (glyphSet.ranges[offset++] + (glyphSet.ranges[offset++] << 8)); ushort cGlyphs = (ushort) (glyphSet.ranges[offset++] + (glyphSet.ranges[offset++] << 8)); unicodeRanges[i] = new UnicodeRange(dc, wcLow, (ushort) (wcLow + cGlyphs - 1)); } }
/// <summary> /// Loads all the unicode ranges. /// </summary> private void LoadRanges(GdiDeviceContent dc) { GlyphSet glyphSet = new GlyphSet(); uint size = LibWrapper.GetFontUnicodeRanges(dc.Handle, glyphSet); if (size == 0) { throw new Exception("Unable to retrieve unicode ranges."); } unicodeRanges = new UnicodeRange[glyphSet.cRanges]; for (int i = 0, offset = 0; i < glyphSet.cRanges; i++) { ushort wcLow = (ushort)(glyphSet.ranges[offset++] + (glyphSet.ranges[offset++] << 8)); ushort cGlyphs = (ushort)(glyphSet.ranges[offset++] + (glyphSet.ranges[offset++] << 8)); unicodeRanges[i] = new UnicodeRange(dc, wcLow, (ushort)(wcLow + cGlyphs - 1)); } }
/// <summary> /// Class constructor. /// </summary> /// <param name="dc">A non-null reference to a wrapper around a GDI device context.</param> public GdiFontEnumerator(GdiDeviceContent dc) { this.dc = dc; }
/// <summary> /// Class constuctor. /// </summary> /// <param name="dc"></param> public GdiUnicodeRanges(GdiDeviceContent dc) { LoadRanges(dc); }
public GdiFontMetrics GetMetrics(GdiDeviceContent dc) { return new GdiFontMetrics(dc, this); }
/// <summary> /// Creates a font whose height is equal to the negative value /// of the EM Square /// </summary> /// <param name="faceName">The typeface name of a font.</param> /// <returns></returns> public static GdiFont CreateDesignFont(string faceName, bool bold, bool italic, GdiDeviceContent dc) { // TODO: Is there a simpler method of obtaining the em-sqaure? GdiFont tempFont = GdiFont.CreateFont(faceName, 2048, bold, italic); dc.SelectFont(tempFont); GdiFontMetrics metrics = tempFont.GetMetrics(dc); tempFont.Dispose(); return(CreateFont(faceName, -Math.Abs(metrics.EmSquare), bold, italic)); }
public GdiFontMetrics GetMetrics(GdiDeviceContent dc) { return(new GdiFontMetrics(dc, this)); }
/// <summary> /// Creates a font whose height is equal to the negative value /// of the EM Square /// </summary> /// <param name="faceName">The typeface name of a font.</param> /// <returns></returns> public static GdiFont CreateDesignFont(string faceName, bool bold, bool italic, GdiDeviceContent dc) { GdiFont tempFont = GdiFont.CreateFont(faceName, 2048, bold, italic); dc.SelectFont(tempFont); GdiFontMetrics metrics = tempFont.GetMetrics(dc); tempFont.Dispose(); return(CreateFont(faceName, -Math.Abs(metrics.EmSquare), bold, italic)); }