Example #1
0
        public static WinGdiFont GetWinGdiFont(RequestFont f)
        {
            if (f == null)
            {
                throw new NotSupportedException();
            }
            if (f == latestFont)
            {
                return(latestWinFont);
            }
            WinGdiFont actualFontInside = WinGdiFont.GetCacheFontAsWinGdiFont(f);

            if (actualFontInside != null)
            {
                return(actualFontInside);
            }
            //-----
            //need to create a new one
            //get register font or create the new one
            FontKey    key = f.FontKey;
            WinGdiFont found;

            if (!registerFonts.TryGetValue(key, out found))
            {
                //create the new one and register
                //create fontface
                FontFaceKey    fontfaceKey = new FontFaceKey(key);
                WinGdiFontFace fontface;
                if (!winGdiFonFaces.TryGetValue(fontfaceKey, out fontface))
                {
                    //create new
                    fontface = new WinGdiFontFace(f.Name);
                    winGdiFonFaces.Add(fontfaceKey, fontface);
                }

                var winGdiFont = new WinGdiFont(fontface, f.SizeInPoints, FontStyle.Regular);
                found = winGdiFont;
                registerFonts.Add(key, found);//cache here
            }
            latestFont = f;
            RequestFontImpl reqFont = (RequestFontImpl)f;

            if (reqFont._platformFont == null)
            {
                reqFont._platformFont = found;
            }

            //found.AssignToRequestFont(f);
            return(latestWinFont = found);
        }
Example #2
0
        public WinGdiFont(WinGdiFontFace fontFace, float sizeInPoints, FontStyle style)
        {
            this.fontFace         = fontFace;
            this.fontSizeInPoints = sizeInPoints;
            this.fontStyle        = style;

            this.fontSizeInPoints = sizeInPoints;
            //this.emSizeInPixels = PixelFarm.Drawing.RequestFont.ConvEmSizeInPointsToPixels(this.fontSizeInPoints);
            this.hfont = InitFont(fontFace.Name, sizeInPoints, style);
            //------------------------------------------------------------------
            //create gdi font from font data
            //build font matrix             ;
            WinGdiTextService.MeasureCharWidths(hfont, out charWidths, out charAbcWidths);
            //float scale = fontFace.GetScale(sizeInPoints);
            //ascendInPixels = fontFace.AscentInDzUnit * scale;
            //descentInPixels = fontFace.DescentInDzUnit * scale;
            //linegapInPixels = fontFace.LineGapInDzUnit * scale;

            //------------------------------------------------------------------


            //int emHeightInDzUnit = f.FontFamily.GetEmHeight(f.Style);
            //this.ascendInPixels = Font.ConvEmSizeInPointsToPixels((f.FontFamily.GetCellAscent(f.Style) / emHeightInDzUnit));
            //this.descentInPixels = Font.ConvEmSizeInPointsToPixels((f.FontFamily.GetCellDescent(f.Style) / emHeightInDzUnit));

            ////--------------
            ////we build font glyph, this is just win32 glyph
            ////
            //int j = charAbcWidths.Length;
            //fontGlyphs = new FontGlyph[j];
            //for (int i = 0; i < j; ++i)
            //{
            //    FontGlyph glyph = new FontGlyph();
            //    glyph.horiz_adv_x = charWidths[i] << 6;
            //    fontGlyphs[i] = glyph;
            //}
        }