Esempio n. 1
0
 public RGFont GetFont(string name, double size, Drawing.Text.FontStyles style)
 {
     return(this.resourceManager.GetTypeface(name, FontWeights.Normal, System.Windows.FontStyles.Normal, FontStretches.Normal));
 }
Esempio n. 2
0
        private static ResourcePoolManager resourcePoolManager;        // = new ResourcePoolManager();

        internal static Graphics.Size MeasureText(IRenderer r, string text, string fontName, float fontSize, Drawing.Text.FontStyles style)
        {
            ResourcePoolManager resManager;
            Font font = null;

            if (r == null)
            {
                if (resourcePoolManager == null)
                {
                    resourcePoolManager = new ResourcePoolManager();
                }

                resManager = resourcePoolManager;
            }
            else
            {
                resManager = r.ResourcePoolManager;
            }

            font = resManager.GetFont(fontName, fontSize, ToWFFontStyle(style));

            if (font == null)
            {
                return(Graphics.Size.Zero);
            }

            var g = ResourcePoolManager.CachedGDIGraphics;

            lock (g)
            {
                lock (sf)
                {
                    var size = ResourcePoolManager.CachedGDIGraphics.MeasureString(text, font, 99999999, sf);

                    size.Width  += 2;
                    size.Height += 2;

                    return(size);
                }
            }
        }
Esempio n. 3
0
        private static ResourcePoolManager resourcePoolManager;        // = new ResourcePoolManager();

        internal static Graphics.Size MeasureText(IRenderer r, string text, string fontName, double fontSize, Drawing.Text.FontStyles style)
        {
            ResourcePoolManager resManager;
            Typeface            typeface = null;

            if (r == null)
            {
                if (resourcePoolManager == null)
                {
                    resourcePoolManager = new ResourcePoolManager();
                }

                resManager = resourcePoolManager;
            }
            else
            {
                resManager = r.ResourcePoolManager;
            }

            typeface = resManager.GetTypeface(fontName, FontWeights.Regular, ToWPFFontStyle(style), FontStretches.Normal);

            if (typeface == null)
            {
                return(Graphics.Size.Zero);
            }

            //var typeface = new System.Windows.Media.Typeface(
            //			new System.Windows.Media.FontFamily(fontName),
            //			PlatformUtility.ToWPFFontStyle(this.fontStyles),
            //			(this.fontStyles & FontStyles.Bold) == FontStyles.Bold ?
            //			System.Windows.FontWeights.Bold : System.Windows.FontWeights.Normal,
            //			System.Windows.FontStretches.Normal);

            System.Windows.Media.GlyphTypeface glyphTypeface;

            double totalWidth = 0;

            if (typeface.TryGetGlyphTypeface(out glyphTypeface))
            {
                //fontInfo.Ascent = typeface.FontFamily.Baseline;
                //fontInfo.LineHeight = typeface.CapsHeight;

                var size = fontSize * 1.33d;

                //this.GlyphIndexes.Capacity = text.Length;

                for (int n = 0; n < text.Length; n++)
                {
                    ushort glyphIndex = glyphTypeface.CharacterToGlyphMap[text[n]];
                    //GlyphIndexes.Add(glyphIndex);

                    double width = glyphTypeface.AdvanceWidths[glyphIndex] * size;
                    //this.TextSizes.Add(width);

                    totalWidth += width;
                }
            }

            return(new Graphics.Size(totalWidth, typeface.CapsHeight));
        }
Esempio n. 4
0
        internal static Graphics.Size MeasureText(DrawingContext dc, string text, string fontName, double fontSize, Drawing.Text.FontStyles style)
        {
            ResourcePoolManager resManager = dc.Renderer.ResourcePoolManager;

            FormattedText ft = new FormattedText(text, System.Threading.Thread.CurrentThread.CurrentCulture,
                                                 FlowDirection.LeftToRight, resManager.GetTypeface(fontName),
                                                 fontSize * PlatformUtility.GetDPI() / 72.0, null);

            return(new Graphics.Size(ft.Width, ft.Height));
        }