A very lightweight wrapper around a Win32 device context
Inheritance: IDisposable
Exemplo n.º 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);
 }
Exemplo n.º 2
0
 public GdiFontCreator(GdiDeviceContent dc)
 {
     this.dc     = dc;
     this.header = new TrueTypeHeader();
     this.ms     = new MemoryStream();
     this.fs     = new FontFileStream(ms);
 }
Exemplo n.º 3
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();
        }
Exemplo n.º 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;
 }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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;
 }
Exemplo n.º 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));
            }
        }
Exemplo n.º 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();
        }
Exemplo n.º 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;
 }
Exemplo n.º 11
0
 public GdiFontCreator(GdiDeviceContent dc) {
     this.dc = dc;
     this.header = new TrueTypeHeader();
     this.ms = new MemoryStream();
     this.fs = new FontFileStream(ms);
 }
Exemplo n.º 12
0
 /// <summary>
 ///     Class constuctor.
 /// </summary>
 /// <param name="dc"></param>
 public GdiUnicodeRanges(GdiDeviceContent dc)
 {
     LoadRanges(dc);
 }
Exemplo n.º 13
0
 public GdiFontMetrics GetMetrics(GdiDeviceContent dc) {
     return new GdiFontMetrics(dc, this);
 }
Exemplo n.º 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;
 }
Exemplo n.º 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));
        }
Exemplo n.º 16
0
 /// <summary>
 ///     Class constuctor.
 /// </summary>
 /// <param name="dc"></param>
 public GdiUnicodeRanges(GdiDeviceContent dc) {
     LoadRanges(dc);
 }
Exemplo n.º 17
0
 public GdiFontMetrics GetMetrics(GdiDeviceContent dc)
 {
     return(new GdiFontMetrics(dc, this));
 }
Exemplo n.º 18
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)
        {
            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));
        }