A very lightweight wrapper around a Win32 device context
Inheritance: IDisposable
示例#1
0
 /// <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);
 }
示例#2
0
 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();
        }
示例#4
0
 /// <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;
 }
示例#5
0
文件: GdiFont.cs 项目: nholik/Fo.Net
        /// <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>
 ///     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;
 }
示例#7
0
        /// <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));
            }
        }
示例#9
0
        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();
        }
示例#10
0
 /// <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;
 }
示例#11
0
 public GdiFontCreator(GdiDeviceContent dc) {
     this.dc = dc;
     this.header = new TrueTypeHeader();
     this.ms = new MemoryStream();
     this.fs = new FontFileStream(ms);
 }
 /// <summary>
 ///     Class constuctor.
 /// </summary>
 /// <param name="dc"></param>
 public GdiUnicodeRanges(GdiDeviceContent dc)
 {
     LoadRanges(dc);
 }
示例#13
0
文件: GdiFont.cs 项目: nholik/Fo.Net
 public GdiFontMetrics GetMetrics(GdiDeviceContent dc) {
     return new GdiFontMetrics(dc, this);
 }
示例#14
0
 /// <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;
 }
示例#15
0
        /// <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));
        }
示例#16
0
 /// <summary>
 ///     Class constuctor.
 /// </summary>
 /// <param name="dc"></param>
 public GdiUnicodeRanges(GdiDeviceContent dc) {
     LoadRanges(dc);
 }
示例#17
0
 public GdiFontMetrics GetMetrics(GdiDeviceContent dc)
 {
     return(new GdiFontMetrics(dc, this));
 }
示例#18
0
文件: GdiFont.cs 项目: nholik/FO.Net
        /// <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));
        }