예제 #1
0
        /// <summary>
        /// Create the outline geometry based on the formatted text.
        /// </summary>
        public static void CreateText(string Text, FontFamily Font = null, bool Bold = false, bool Italic = false)
        {
            System.Windows.FontStyle fontStyle = FontStyles.Normal;
            FontWeight fontWeight = FontWeights.Medium;

            if (Bold == true)
            {
                fontWeight = FontWeights.Bold;
            }
            if (Italic == true)
            {
                fontStyle = FontStyles.Italic;
            }
            if (null == Font)
            {
                Font = new FontFamily("Arial");
            }

            // Create the formatted text based on the properties set.
            FormattedText formattedText = new FormattedText(
                Text,
                CultureInfo.GetCultureInfo("en-us"),
                FlowDirection.LeftToRight,
                new Typeface(
                    Font,
                    fontStyle,
                    fontWeight,
                    FontStretches.Normal),
                _fontSize,
                System.Windows.Media.Brushes.Black // This brush does not matter since we use the geometry of the text.
                );

            // Build the geometry object that represents the text.
            _textGeometry = formattedText.BuildGeometry(new System.Windows.Point(0, 0));
        }
예제 #2
0
        public void CreateText()
        {
            System.Windows.FontStyle fontStyle = FontStyles.Normal;
            FontWeight fontWeight = FontWeights.Bold;

            //if (Bold == true) fontWeight = FontWeights.Bold;
            //if (Italic == true) fontStyle = FontStyles.Italic;

            string upperCaseText = Text.ToUpper();


            // Create the formatted text based on the properties set.
            FormattedText formattedText = new FormattedText(
                upperCaseText,
                CultureInfo.GetCultureInfo("en-us"),
                FlowDirection.LeftToRight,
                new Typeface(
                    FontFamily,
                    fontStyle,
                    fontWeight,
                    FontStretches.Normal),
                FontSize,
                System.Windows.Media.Brushes.Black                 // This brush does not matter since we use the geometry of the text.
                );

            // Build the geometry object that represents the text.
            _textGeometry = formattedText.BuildGeometry(new System.Windows.Point(0, 0));

            // Build the geometry object that represents the text hightlight.
            //if (Highlight == true)
            //{
            //    _textHighLightGeometry = formattedText.BuildHighlightGeometry(new System.Windows.Point(0, 0));
            //}
        }
예제 #3
0
        // copied and adapted from presenter::GetLabelWidthAndHeight(...)
        private double TestHelper_GetLabelWidthAndHeight(string text)
        {
            var defaultFontFamily  = new System.Windows.Media.FontFamily();
            var defaultFontStyle   = new System.Windows.FontStyle();
            var defaultFontStretch = new System.Windows.FontStretch();
            var defaultFontSizeEm  = 12.0;

            var typeFace = new Typeface(defaultFontFamily,
                                        defaultFontStyle,
                                        System.Windows.FontWeights.Normal,
                                        defaultFontStretch);

            var formattedText = new FormattedText(
                text,
                System.Globalization.CultureInfo.CurrentUICulture,
                FlowDirection.LeftToRight,
                typeFace,
                defaultFontSizeEm,
                Brushes.Black);

            var Padding = 15;   // empirical
            var width   = formattedText.Width + Padding;

            return(width);
        }
예제 #4
0
        public bool DrawString(
            System.Windows.Media.DrawingContext graphics,
            System.Windows.Media.FontFamily fontFamily,
            System.Windows.FontStyle fontStyle,
            System.Windows.FontWeight fontWeight,
            double fontSize,
            string strText,
            System.Windows.Point ptDraw,
            System.Globalization.CultureInfo ci)
        {
            Geometry path = GDIPath.CreateTextGeometry(strText, fontFamily, fontStyle, fontWeight, fontSize, ptDraw, ci);

            for (int i = 1; i <= m_nThickness; ++i)
            {
                SolidColorBrush solidbrush = new SolidColorBrush(m_clrOutline);

                Pen pen = new Pen(solidbrush, i);
                pen.LineJoin = PenLineJoin.Round;
                if (m_bClrText)
                {
                    SolidColorBrush brush = new SolidColorBrush(m_clrText);
                    graphics.DrawGeometry(brush, pen, path);
                }
                else
                {
                    graphics.DrawGeometry(m_brushText, pen, path);
                }
            }

            return(true);
        }
예제 #5
0
        private static ImageSource CreateGlyph(string text, FontFamily fontFamily, FontStyle fontStyle, FontWeight fontWeight, FontStretch fontStretch, Brush foreBrush)
        {
            if (fontFamily != null && !string.IsNullOrEmpty(text))
            {
                var typeface = new Typeface(fontFamily, fontStyle, fontWeight, fontStretch);

                GlyphTypeface glyphTypeface;
                if (!typeface.TryGetGlyphTypeface(out glyphTypeface))
                {
                    throw Log.ErrorAndCreateException <InvalidOperationException>("No glyph type face found");
                }

                var glyphIndexes  = new ushort[text.Length];
                var advanceWidths = new double[text.Length];

                for (var i = 0; i < text.Length; i++)
                {
                    ushort glyphIndex;

                    try
                    {
                        var key = text[i];

                        if (!glyphTypeface.CharacterToGlyphMap.TryGetValue(key, out glyphIndex))
                        {
                            glyphIndex = 42;
                        }
                    }
                    catch (Exception)
                    {
                        glyphIndex = 42;
                    }

                    glyphIndexes[i] = glyphIndex;

                    var width = glyphTypeface.AdvanceWidths[glyphIndex] * 1.0;
                    advanceWidths[i] = width;
                }

                try
                {
                    var glyphRun        = new GlyphRun(glyphTypeface, 0, false, RenderingEmSize, glyphIndexes, new Point(0, 0), advanceWidths, null, null, null, null, null, null);
                    var glyphRunDrawing = new GlyphRunDrawing(foreBrush, glyphRun);

                    //TextOptions.SetTextRenderingMode(glyphRunDrawing, TextRenderingMode.Aliased);

                    var drawingImage = new DrawingImage(glyphRunDrawing);

                    //TextOptions.SetTextRenderingMode(drawingImage, TextRenderingMode.Aliased);

                    return(drawingImage);
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Error in generating Glyphrun");
                }
            }

            return(null);
        }
예제 #6
0
        public GraphicsText(
            string text,
            double left, 
            double top, 
            double right, 
            double bottom,
            Color objectColor,
            double textFontSize,
            string textFontFamilyName,
            FontStyle textFontStyle,
            FontWeight textFontWeight,
            FontStretch textFontStretch,
            double actualScale)
        {
            this.text = text;
            this.rectangleLeft = left;
            this.rectangleTop = top;
            this.rectangleRight = right;
            this.rectangleBottom = bottom;
            this.graphicsObjectColor = objectColor;
            this.textFontSize = textFontSize;
            this.textFontFamilyName = textFontFamilyName;
            this.textFontStyle = textFontStyle;
            this.textFontWeight = textFontWeight;
            this.textFontStretch = textFontStretch;
            this.graphicsActualScale = actualScale;

            graphicsLineWidth = 2;      // used for drawing bounding rectangle when selected

            //RefreshDrawng();
        }
예제 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FontInfo"/> class.
 /// </summary>
 /// <param name="family">The family.</param>
 /// <param name="size">The size.</param>
 /// <param name="style">The style.</param>
 /// <param name="weight">The weight.</param>
 public FontInfo(FontFamily family, double size, FontStyle style, FontWeight weight)
 {
     FontFamily = family;
     FontSize = size;
     FontStyle = style;
     FontWeight = weight;
 }
예제 #8
0
        private void getformattedText(string str)
        {
            System.Windows.FontStyle fontStyle = FontStyles.Normal;
            FontWeight fontWeight = FontWeights.Normal;
            // Create the formatted text based on the properties set.
            FormattedText formattedText = new FormattedText(
                str,
                CultureInfo.GetCultureInfo("en-us"),
                FlowDirection.LeftToRight,
                new Typeface(
                    FontFamily,
                    FontStyle,
                    FontWeight,
                    FontStretch),
                FontSize,
                System.Windows.Media.Brushes.Black // This brush does not matter since we use the geometry of the text.
                );

            this.Width  = formattedText.Width;
            this.Height = formattedText.Height;
            // Build the geometry object that represents the text.
            //pg.AddGeometry(formattedText.BuildGeometry(new System.Windows.Point(5, 5)));
            TextGeometry = formattedText.BuildGeometry(new System.Windows.Point(0, 0));
            // Build the geometry object that represents the text hightlight.
            if (Highlight == true)
            {
                TextHighLightGeometry = formattedText.BuildHighlightGeometry(new System.Windows.Point(0, 0));
            }
        }
예제 #9
0
 public object SetStyle(object handle, FontStyle style)
 {
     var font = (FontData)handle;
     font = font.Clone ();
     font.Style = DataConverter.ToWpfFontStyle (style);
     return font;
 }
예제 #10
0
 public DesignerFont()
 {
     FontColor  = new SolidColorBrush(Color.FromRgb(0, 0, 0));
     FontSize   = 24;
     FontFamily = new FontFamily("微软雅黑");
     FontStyle  = new System.Windows.FontStyle();
 }
예제 #11
0
        internal Size MeasureText(string text, FontFamily fontFamily, FontStyle fontStyle,
            FontWeight fontWeight,
            FontStretch fontStretch, double fontSize)
        {
            var typeface = new Typeface(fontFamily, fontStyle, fontWeight, fontStretch);
            GlyphTypeface glyphTypeface;

            if (!typeface.TryGetGlyphTypeface(out glyphTypeface))
            {
                return MeasureTextSize(text, fontFamily, fontStyle, fontWeight, fontStretch, fontSize);
            }

            double totalWidth = 0;
            double height = 0;

            foreach (var t in text)
            {
                var glyphIndex = glyphTypeface.CharacterToGlyphMap[t];
                var width = glyphTypeface.AdvanceWidths[glyphIndex] * fontSize;
                var glyphHeight = glyphTypeface.AdvanceHeights[glyphIndex] * fontSize;

                if (glyphHeight > height)
                {
                    height = glyphHeight;
                }
                totalWidth += width;
            }
            return new Size(totalWidth, height);
        }
예제 #12
0
파일: Helper.cs 프로젝트: wwwK/EntityDB
        /// <summary>
        /// 计算文本显示宽、高
        /// </summary>
        public static MeasureSize MeasureText(string text,
                                              System.Windows.Media.FontFamily fontFamily,
                                              System.Windows.FontStyle fontStyle,
                                              System.Windows.FontWeight fontWeight,
                                              System.Windows.FontStretch fontStretch,
                                              double fontSize)
        {
            System.Windows.Media.Typeface      typeface = new System.Windows.Media.Typeface(fontFamily, fontStyle, fontWeight, fontStretch);
            System.Windows.Media.GlyphTypeface glyphTypeface;
            if (!typeface.TryGetGlyphTypeface(out glyphTypeface))
            {
                return(MeasureTextSize(text, fontFamily, fontStyle, fontWeight, fontStretch, fontSize));
            }
            double totalWidth = 0;
            double height     = 0;

            for (int n = 0; n < text.Length; n++)
            {
                ushort glyphIndex  = glyphTypeface.CharacterToGlyphMap[text[n]];
                double width       = glyphTypeface.AdvanceWidths[glyphIndex] * fontSize;
                double glyphHeight = glyphTypeface.AdvanceHeights[glyphIndex] * fontSize;
                if (glyphHeight > height)
                {
                    height = glyphHeight;
                }
                totalWidth += width;
            }
            return(new MeasureSize(totalWidth, height));
        }
예제 #13
0
        public bool DrawString(
            System.Windows.Media.DrawingContext graphics,
            System.Windows.Media.FontFamily fontFamily,
            System.Windows.FontStyle fontStyle,
            System.Windows.FontWeight fontWeight,
            double fontSize,
            string strText,
            System.Windows.Point ptDraw,
            System.Globalization.CultureInfo ci)
        {
            Geometry path = GDIPath.CreateTextGeometry(strText, fontFamily, fontStyle, fontWeight, fontSize, ptDraw, ci);

            if (m_bClrText)
            {
                SolidColorBrush brush = new SolidColorBrush(m_clrText);
                Pen             pen   = new Pen(new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)), 1.0);
                graphics.DrawGeometry(brush, pen, path);
            }
            else
            {
                Pen pen = new Pen(new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)), 1.0);
                graphics.DrawGeometry(m_brushText, pen, path);
            }
            return(true);
        }
예제 #14
0
 public FontHandler(swm.FontFamily family, double size, sw.FontStyle style, sw.FontWeight weight)
 {
     Family        = new FontFamily(new FontFamilyHandler(family));
     Size          = size;
     WpfFontStyle  = style;
     WpfFontWeight = weight;
 }
예제 #15
0
        /// <summary>
        /// Create the outline geometry based on the formatted text.
        /// </summary>
        /// <param name="text"></param>
        /// <param name="bold"></param>
        /// <param name="italic"></param>
        /// <param name="family"></param>
        /// <param name="size"></param>
        /// <param name="location"></param>
        /// <returns></returns>
        private PathGeometry CreateText(string text, bool bold, bool italic, FontFamily family, double size, System.Windows.Point location)
        {
            System.Windows.FontStyle fontStyle = FontStyles.Normal;
            FontWeight fontWeight = FontWeights.Medium;

            if (bold == true)
            {
                fontWeight = FontWeights.Bold;
            }

            if (italic == true)
            {
                fontStyle = FontStyles.Italic;
            }

            System.Windows.Media.FormattedText formattedText = new System.Windows.Media.FormattedText(
                text,
                System.Globalization.CultureInfo.GetCultureInfo("en-us"),
                FlowDirection.LeftToRight,
                new Typeface(family, fontStyle, fontWeight, FontStretches.Normal),
                size, System.Windows.Media.Brushes.Black
                );

            Geometry textGeometry = formattedText.BuildGeometry(location);

            return(textGeometry.GetFlattenedPathGeometry());
        }
예제 #16
0
파일: FontHandler.cs 프로젝트: sami1971/Eto
 public FontHandler(Eto.Generator generator, swm.FontFamily family, double size, sw.FontStyle style, sw.FontWeight weight)
 {
     Family        = new FontFamily(generator, new FontFamilyHandler(family));
     Size          = size;
     WpfFontStyle  = style;
     WpfFontWeight = weight;
 }
예제 #17
0
        public static Size MeasureSize(string text, FontFamily fontFamily, double fontSize)
        {
            if (text == null)
            {
                text = "";
            }

            System.Windows.FontStyle fontStyle = FontStyles.Normal;
            FontWeight fontWeight    = FontWeights.Medium;
            var        formattedText = new FormattedText(
                text,
                CultureInfo.CurrentCulture,
                FlowDirection.LeftToRight,
                new Typeface(
                    fontFamily,
                    fontStyle,
                    fontWeight,
                    FontStretches.Normal),
                fontSize,
                System.Windows.Media.Brushes.Black
                );
            Geometry _textGeometry          = formattedText.BuildGeometry(new System.Windows.Point(0, 0));
            Geometry _textHighLightGeometry = formattedText.BuildHighlightGeometry(new System.Windows.Point(0, 0));

            return(_textHighLightGeometry == null ? new Size(0, 0) : _textHighLightGeometry.Bounds.Size);
        }
예제 #18
0
        public static SW.FontStyle ToWpfFontStyle(FontStyle value)
        {
            if (value == FontStyle.Italic) return SW.FontStyles.Italic;
            if (value == FontStyle.Oblique) return SW.FontStyles.Oblique;

            return SW.FontStyles.Normal;
        }
예제 #19
0
 public Font()
 {
     Weight = FontWeights.Normal;
     Family = Fonts.SystemFontFamilies.ToArray<FontFamily>()[0];
     Size = 15;
     Stretch = FontStretches.Normal;
     Style = FontStyles.Normal;
 }
 public WpfRichTextBoxWordColoringRule(string text, string textColor, string backgroundColor, FontStyle fontStyle, FontWeight fontWeight)
 {
     Text = text;
     FontColor = textColor;
     BackgroundColor = backgroundColor;
     Style = fontStyle;
     Weight = fontWeight;
 }
예제 #21
0
 public WpfFontFamilyInfo(FontFamily family, FontWeight weight, 
     FontStyle style, FontStretch stretch)
 {
     _family  = family;
     _weight  = weight;
     _style   = style;
     _stretch = stretch;
 }
 public WpfRichTextBoxRowColoringRule(string condition, string fontColor, string backColor, FontStyle fontStyle, FontWeight fontWeight)
 {
     this.Condition = condition;
     this.FontColor = fontColor;
     this.BackgroundColor = backColor;
     this.Style = fontStyle;
     this.Weight = fontWeight;
 }
예제 #23
0
 public ColorRule(string condition, Brush foregroundColor, Brush backgroundColor, FontStyle fontStyle, FontWeight fontWeight)
 {
     this.Condition = condition;
     this.ForegroundColor = foregroundColor;
     this.BackgroundColor = backgroundColor;
     this.FontStyle = fontStyle;
     this.FontWeight = fontWeight;
 }
 public WpfRichTextBoxWordColoringRule(string text, string textColor, string backgroundColor, FontStyle fontStyle, FontWeight fontWeight)
 {
     this.Text = text;
     this.FontColor = textColor;
     this.BackgroundColor = backgroundColor;
     this.Style = fontStyle;
     this.Weight = fontWeight;
 }
 public WpfRichTextBoxRowColoringRule(string condition, string fontColor, string backColor, FontStyle fontStyle, FontWeight fontWeight)
 {
     Condition = condition;
     FontColor = fontColor;
     BackgroundColor = backColor;
     Style = fontStyle;
     Weight = fontWeight;
 }
예제 #26
0
        public static ImageSource ToFontAwesomeIcon(this string text, Brush foreBrush, FontStyle fontStyle, FontWeight fontWeight, FontStretch fontStretch)
        {
            var fontFamily = new FontFamily("/GitWorkItems;component/Resources/#FontAwesome");
            if (fontFamily != null && !String.IsNullOrEmpty(text))
            {
                //premier essai, on charge la police directement
                Typeface typeface = new Typeface(fontFamily, fontStyle, fontWeight, fontStretch);

                GlyphTypeface glyphTypeface;
                if (!typeface.TryGetGlyphTypeface(out glyphTypeface))
                {
                    //si ça ne fonctionne pas (et pour le mode design dans certains cas) on ajoute l'uri pack://application
                    typeface = new Typeface(new FontFamily(new Uri("pack://application:,,,"), fontFamily.Source), fontStyle, fontWeight, fontStretch);
                    if (!typeface.TryGetGlyphTypeface(out glyphTypeface))
                        throw new InvalidOperationException("No glyphtypeface found");
                }

                //détermination des indices/tailles des caractères dans la police
                ushort[] glyphIndexes = new ushort[text.Length];
                double[] advanceWidths = new double[text.Length];

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

                    }
                    catch (Exception)
                    {
                        glyphIndex = 42;
                    }
                    glyphIndexes[n] = glyphIndex;

                    double width = glyphTypeface.AdvanceWidths[glyphIndex] * 1.0;
                    advanceWidths[n] = width;
                }

                try
                {

                    //création de l'objet DrawingImage (compatible avec Imagesource) à partir d'un glyphrun
                    GlyphRun gr = new GlyphRun(glyphTypeface, 0, false, 1.0, glyphIndexes,
                                                                         new Point(0, 0), advanceWidths, null, null, null, null, null, null);

                    GlyphRunDrawing glyphRunDrawing = new GlyphRunDrawing(foreBrush, gr);
                    return new DrawingImage(glyphRunDrawing);
                }
                catch (Exception ex)
                {
                    // ReSharper disable LocalizableElement
                    Console.WriteLine("Error in generating Glyphrun : " + ex.Message);
                    // ReSharper restore LocalizableElement
                }
            }
            return null;
        }
예제 #27
0
 public DriveFontConfiguration(ExplorerTreeViewModel explorerTreeVM)
 {
     this.ExplorerTreeVM = explorerTreeVM;
     this.fontFamily     = new System.Windows.Media.FontFamily("Times New Roman");
     this.fontSize       = 12;
     this.fontStrech     = FontStretches.Normal;
     this.fontStyle      = FontStyles.Normal;
     this.fontWeight     = FontWeights.Normal;
 }
예제 #28
0
 void avAddressCtrl_Loaded(object sender, EventArgs e)
 {
     initBackBrush = (SolidColorBrush)wpfAddressCtrl.MyControl_Background;
     initForeBrush = wpfAddressCtrl.MyControl_Foreground;
     initFontFamily = wpfAddressCtrl.MyControl_FontFamily;
     initFontSize = wpfAddressCtrl.MyControl_FontSize;
     initFontWeight = wpfAddressCtrl.MyControl_FontWeight;
     initFontStyle = wpfAddressCtrl.MyControl_FontStyle;
 }
예제 #29
0
 void avAddressCtrl_Loaded(object sender, EventArgs e)
 {
     initBackBrush  = (SolidColorBrush)wpfAddressCtrl.MyControl_Background;
     initForeBrush  = wpfAddressCtrl.MyControl_Foreground;
     initFontFamily = wpfAddressCtrl.MyControl_FontFamily;
     initFontSize   = wpfAddressCtrl.MyControl_FontSize;
     initFontWeight = wpfAddressCtrl.MyControl_FontWeight;
     initFontStyle  = wpfAddressCtrl.MyControl_FontStyle;
 }
예제 #30
0
		public FontInfo(FontFamily fam, double sz, FontStyle style, FontStretch strc, FontWeight weight, SolidColorBrush c)
		{
			this.Family = fam;
			this.Size = sz;
			this.Style = style;
			this.Stretch = strc;
			this.Weight = weight;
			this.BrushColor = c;
		}
예제 #31
0
파일: Font.cs 프로젝트: catwalkagogo/Heron
 public Font(FontFamily family, double size, FontStyle style, FontWeight weight, FontStretch stretch)
     : this()
 {
     this.Family = family;
     this.Size = size;
     this.Style = style;
     this.Weight = weight;
     this.Stretch = stretch;
 }
예제 #32
0
 private void avAddressCtrl_Loaded(object sender, EventArgs e)
 {
     _initBackBrush = _wpfAddressCtrl.MyControlBackground;
     _initForeBrush = _wpfAddressCtrl.MyControlForeground;
     _initFontFamily = _wpfAddressCtrl.MyControlFontFamily;
     _initFontSize = _wpfAddressCtrl.MyControlFontSize;
     _initFontWeight = _wpfAddressCtrl.MyControlFontWeight;
     _initFontStyle = _wpfAddressCtrl.MyControlFontStyle;
 }
예제 #33
0
        public static Size GetScreenSize(this string text, FontFamily fontFamily, double fontSize, FontStyle fontStyle, FontWeight fontWeight, FontStretch fontStretch) {
            fontFamily = fontFamily ?? new TextBlock().FontFamily;
            fontSize = fontSize > 0 ? fontSize : new TextBlock().FontSize;

            var typeface = new Typeface(fontFamily, fontStyle, fontWeight, fontStretch);
            var ft = new FormattedText(text ?? string.Empty, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, fontSize, Brushes.Black);

            return new Size(ft.Width, ft.Height);
        }
예제 #34
0
 public override object Create(string fontName, double size, FontStyle style, FontWeight weight, FontStretch stretch)
 {
     size = GetPointsFromDeviceUnits (size);
     return new FontData (new FontFamily (fontName), size) {
         Style = style.ToWpfFontStyle (),
         Weight = weight.ToWpfFontWeight (),
         Stretch = stretch.ToWpfFontStretch ()
     };
 }
예제 #35
0
 public TextContext()
 {
     fontFamily = new System.Windows.Media.FontFamily("Arial");
     fontStyle  = new System.Windows.FontStyle();
     nfontSize  = 20;
     pszText    = null;
     ptDraw     = new System.Windows.Point(0, 0);
     ci         = new System.Globalization.CultureInfo("en-US");
 }
 void Reset()
 {
     root.Blocks.Clear();
     currentFontStyle = FontStyles.Normal;
     currentFontWeight = FontWeights.Normal;
     currentUnderline = false;
     currentStrike = false;
     isHyperlink = false;
 }
예제 #37
0
파일: Font.cs 프로젝트: guidgets/XamlGrid
 public Font(FontFamily family, double size, FontStretch stretch, FontStyle style, FontWeight weight, Color foreground)
     : this()
 {
     this.Family = family;
     this.Size = size;
     this.Stretch = stretch;
     this.Style = style;
     this.Weight = weight;
     this.Foreground = foreground;
 }
예제 #38
0
 public FontStyleData(string name, FontStyle fontStyle, FontWeight fontWeight, TextDecorationLocation? textDecoration, FontVariants fontVariant, FontCapitals fontCapitals, double fontSize)
 {
     _name = name;
     _fontStyle = fontStyle;
     _fontWeight = fontWeight;
     _textDecoration = textDecoration;
     _fontVariant = fontVariant;
     _fontCapitals = fontCapitals;
     _fontSize = fontSize;
 }
예제 #39
0
 public static Size MeasureText(string text, FontFamily fontFamily, FontStyle fontStyle, FontWeight fontWeight, FontStretch fontStretch, double fontSize)
 {
     FormattedText ft = new FormattedText(text,
                                          CultureInfo.CurrentCulture,
                                          FlowDirection.LeftToRight,
                                          new Typeface(fontFamily, fontStyle, fontWeight, fontStretch),
                                          fontSize,
                                          Brushes.Black);
     return new Size(ft.Width, ft.Height);
 }
예제 #40
0
        private static GlyphRun GetGlyphRun(string text, FontFamily fontFamily, FontStyle fontStyle, FontWeight fontWeight, FontStretch fontStretch)
        {
            if (fontFamily != null && !string.IsNullOrEmpty(text))
            {
                var typeface = new Typeface(fontFamily, fontStyle, fontWeight, fontStretch);

                GlyphTypeface glyphTypeface;
                if (!typeface.TryGetGlyphTypeface(out glyphTypeface))
                {
                    throw Log.ErrorAndCreateException <InvalidOperationException>("No glyph type face found");
                }

                var glyphIndexes  = new ushort[text.Length];
                var advanceWidths = new double[text.Length];

                for (var i = 0; i < text.Length; i++)
                {
                    ushort glyphIndex;

                    try
                    {
                        var key = text[i];

                        if (!glyphTypeface.CharacterToGlyphMap.TryGetValue(key, out glyphIndex))
                        {
                            glyphIndex = 42;
                        }
                    }
                    catch (Exception)
                    {
                        glyphIndex = 42;
                    }

                    glyphIndexes[i] = glyphIndex;

                    var width = glyphTypeface.AdvanceWidths[glyphIndex] * 1.0;
                    advanceWidths[i] = width;
                }

                try
                {
#pragma warning disable 618
                    var glyphRun = new GlyphRun(glyphTypeface, 0, false, RenderingEmSize, glyphIndexes, new Point(0, 0), advanceWidths, null, null, null, null, null, null);
#pragma warning restore 618
                    return(glyphRun);
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Error in generating Glyphrun");
                }
            }

            return(null);
        }
예제 #41
0
 public static void SetSvgFontStyle(this HtmlElement element, System.Windows.FontStyle fontStyle, SvgValueConverter converter)
 {
     if (fontStyle == System.Windows.FontStyle.Normal)
     {
         element.ClearHtmlStyleProperty("font-style");
     }
     else
     {
         element.SetSvgAttribute("font-style", converter.ToFontStyleString(fontStyle));
     }
 }
예제 #42
0
 public TrayIconRenderer()
 {
     this.iconSize = System.Windows.Forms.SystemInformation.IconSize.Height / 2;
     double scalingFactor = this.iconSize / DefaultTrayIconSize;
     this.fontSize = DefaultTrayFontSize * scalingFactor;
     this.foreground = new SolidColorBrush(Colors.White);
     this.CultureInfo = new CultureInfo("en-us");
     this.fontFamily = new FontFamily(DefaultFontFamily);
     this.fontStyle = FontStyles.Normal;
     this.fontWeight = FontWeights.SemiBold;
     UpdateTypeface();
 }
        public RuleOptions(XElement rule)
        {
            string ignoreCaseStr = rule.Element("IgnoreCase").Value.Trim();
            string foregroundStr = rule.Element("Foreground").Value.Trim();
            string fontWeightStr = rule.Element("FontWeight").Value.Trim();
            string fontStyleStr = rule.Element("FontStyle").Value.Trim();

            IgnoreCase = bool.Parse(ignoreCaseStr);
            Foreground = (Brush)new BrushConverter().ConvertFrom(foregroundStr);
            FontWeight = (FontWeight)new FontWeightConverter().ConvertFrom(fontWeightStr);
            FontStyle = (FontStyle)new FontStyleConverter().ConvertFrom(fontStyleStr);
        }
예제 #44
0
 internal MatchingStyle(
     FontStyle       style,
     FontWeight      weight,
     FontStretch     stretch
     )
 {
     _vector = new Vector(
         (stretch.ToOpenTypeStretch() - FontStretches.Normal.ToOpenTypeStretch()) * FontStretchScale,
         style.GetStyleForInternalConstruction() * FontStyleScale,
         (weight.ToOpenTypeWeight() - FontWeights.Normal.ToOpenTypeWeight()) / 100.0 * FontWeightScale
         );
 }
예제 #45
0
        internal static IDictionary<XmlLanguage, string> ConstructFaceNamesByStyleWeightStretch(
            FontStyle style,
            FontWeight weight,
            FontStretch stretch)
        {
            string faceName = BuildFaceName(style, weight, stretch);

            // Default comparer calls CultureInfo.Equals, which works for our purposes.
            Dictionary<XmlLanguage, string> faceNames = new Dictionary<XmlLanguage, string>(1);
            faceNames.Add(XmlLanguage.GetLanguage("en-us"), faceName);
            return faceNames;
        }
예제 #46
0
        private static string BuildFaceName(
            FontStyle fontStyle,
            FontWeight fontWeight,
            FontStretch fontStretch
            )
        {
            string parsedStyleName   = null;
            string parsedWeightName  = null;
            string parsedStretchName = null;
            string regularFaceName   = "Regular";
            if (fontWeight != FontWeights.Normal)
                parsedWeightName = ((IFormattable)fontWeight).ToString(null, CultureInfo.InvariantCulture);

            if (fontStretch != FontStretches.Normal)
                parsedStretchName = ((IFormattable)fontStretch).ToString(null, CultureInfo.InvariantCulture);

            if (fontStyle != FontStyles.Normal)
                parsedStyleName = ((IFormattable)fontStyle).ToString(null, CultureInfo.InvariantCulture);

            // Build correct face string.
            // Set the initial capacity to be able to hold the word "Regular".
            StringBuilder faceNameBuilder = new StringBuilder(7);

            if (parsedStretchName != null)
            {
                faceNameBuilder.Append(parsedStretchName);
            }

            if (parsedWeightName != null)
            {
                if (faceNameBuilder.Length > 0)
                {
                    faceNameBuilder.Append(" ");
                }
                faceNameBuilder.Append(parsedWeightName);
            }

            if (parsedStyleName != null)
            {
                if (faceNameBuilder.Length > 0)
                {
                    faceNameBuilder.Append(" ");
                }
                faceNameBuilder.Append(parsedStyleName);
            }

            if (faceNameBuilder.Length == 0)
            {
                faceNameBuilder.Append(regularFaceName);
            }

            return faceNameBuilder.ToString();
        }         
예제 #47
0
 public static int ConvertToInt(FontStyle font)
 {
     if (font.Equals(FontStyles.Oblique))
     {
         return 1;
     }
     if (font.Equals(FontStyles.Italic))
     {
         return 2;
     }
     return 0;
 }
 static TimedTextStyle()
 {
     DefaultColor = Colors.White;
     DefaultBackgroundColor = Colors.Transparent;
     DefaultExtent = Extent.Auto;
     DefaultFontFamily = new FontFamily("Portable User Interface");
     DefaultFontStyle = FontStyles.Normal;
     DefaultFontWeight = Weight.Normal;
     DefaultOrigin = Origin.Empty;
     DefaultPadding = Padding.Empty;
     DefaultOutlineColor = Colors.Black;
 }
예제 #49
0
        public FontTypeface GetFamilyTypeface(sw.FontStyle fontStyle, sw.FontWeight fontWeight)
        {
            var typefaces = Control.GetTypefaces();

            foreach (var type in typefaces)
            {
                if (type.Style == fontStyle && type.Weight == fontWeight)
                {
                    return(new FontTypeface(Widget, new FontTypefaceHandler(type)));
                }
            }
            return(new FontTypeface(Widget, new FontTypefaceHandler(typefaces.First())));
        }
예제 #50
0
 public Font(string fontFamily       = null, double fontSize = DEFAULT_FONT_SIZE,
             FontStyle fontStyle     = default(FontStyle),
             FontWeight fontWeight   = default(FontWeight),
             FontStretch fontStretch = default(FontStretch),
             Brush foreground        = null)
 {
     FontFamily  = new FontFamily(fontFamily ?? "Arial");
     FontSize    = fontSize;
     FontStyle   = fontStyle;           //?? default(FontStyle);
     FontWeight  = fontWeight;          //?? default(FontWeight);
     FontStretch = fontStretch;         //?? default(FontStretch);
     Foreground  = foreground ?? new SolidColorBrush(Colors.Black);
 }
예제 #51
0
        /// <summary>
        /// Creates a typeface.
        /// </summary>
        public static Typeface CreateTypeface(WpfFontFamily family, XFontStyle style)
        {
            // BUG: does not work with fonts that have others than the four default styles
            WpfFontStyle  fontStyle  = FontStyleFromStyle(style);
            WpfFontWeight fontWeight = FontWeightFromStyle(style);

#if !SILVERLIGHT
            WpfTypeface typeface = new WpfTypeface(family, fontStyle, fontWeight, FontStretches.Normal);
#else
            WpfTypeface typeface = null;
#endif
            return(typeface);
        }
예제 #52
0
        //
        // Font
        //
        public static FontStyle ToXwtFontStyle(SW.FontStyle value)
        {
            // No, SW.FontStyles is not an enum
            if (value == SW.FontStyles.Italic)
            {
                return(FontStyle.Italic);
            }
            if (value == SW.FontStyles.Oblique)
            {
                return(FontStyle.Oblique);
            }

            return(FontStyle.Normal);
        }
예제 #53
0
        public bool DrawString(
            System.Windows.Media.DrawingContext graphics,
            System.Windows.Media.FontFamily fontFamily,
            System.Windows.FontStyle fontStyle,
            System.Windows.FontWeight fontWeight,
            double fontSize,
            string strText,
            System.Windows.Point ptDraw,
            System.Globalization.CultureInfo ci)
        {
            int nOffset = Math.Abs(m_nOffsetX);

            if (Math.Abs(m_nOffsetX) == Math.Abs(m_nOffsetY))
            {
                nOffset = Math.Abs(m_nOffsetX);
            }
            else if (Math.Abs(m_nOffsetX) > Math.Abs(m_nOffsetY))
            {
                nOffset = Math.Abs(m_nOffsetY);
            }
            else if (Math.Abs(m_nOffsetX) < Math.Abs(m_nOffsetY))
            {
                nOffset = Math.Abs(m_nOffsetX);
            }

            for (int i = 0; i < nOffset; ++i)
            {
                Geometry path = GDIPath.CreateTextGeometry(strText, fontFamily, fontStyle, fontWeight, fontSize,
                                                           new Point(ptDraw.X + ((i * (-m_nOffsetX)) / nOffset), ptDraw.Y + ((i * (-m_nOffsetY)) / nOffset)), ci);

                SolidColorBrush solidbrush = new SolidColorBrush(m_clrOutline);

                Pen pen = new Pen(solidbrush, m_nThickness);
                pen.LineJoin = PenLineJoin.Round;

                if (m_bClrText)
                {
                    SolidColorBrush brush = new SolidColorBrush(m_clrText);
                    graphics.DrawGeometry(brush, pen, path);
                }
                else
                {
                    graphics.DrawGeometry(m_brushText, pen, path);
                }
            }

            return(true);
        }
예제 #54
0
        private static ImageSource CreateGlyph(string text, FontFamily fontFamily, FontStyle fontStyle, FontWeight fontWeight, FontStretch fontStretch, Brush foreBrush)
        {
            if (fontFamily != null && !string.IsNullOrEmpty(text))
            {
                var typeface = new Typeface(fontFamily, fontStyle, fontWeight, fontStretch);

                GlyphTypeface glyphTypeface;
                if (!typeface.TryGetGlyphTypeface(out glyphTypeface))
                {
                    Log.ErrorAndThrowException <InvalidOperationException>("No glyph type face found");
                }

                var glyphIndexes  = new ushort[text.Length];
                var advanceWidths = new double[text.Length];
                for (var i = 0; i < text.Length; i++)
                {
                    ushort glyphIndex;

                    try
                    {
                        glyphIndex = glyphTypeface.CharacterToGlyphMap[text[i]];
                    }
                    catch (Exception)
                    {
                        glyphIndex = 42;
                    }

                    glyphIndexes[i] = glyphIndex;

                    var width = glyphTypeface.AdvanceWidths[glyphIndex] * 1.0;
                    advanceWidths[i] = width;
                }

                try
                {
                    var gr = new GlyphRun(glyphTypeface, 0, false, 1.0, glyphIndexes, new Point(0, 0), advanceWidths, null, null, null, null, null, null);
                    var glyphRunDrawing = new GlyphRunDrawing(foreBrush, gr);

                    return(new DrawingImage(glyphRunDrawing));
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Error in generating Glyphrun");
                }
            }

            return(null);
        }
예제 #55
0
파일: Helper.cs 프로젝트: wwwK/EntityDB
 /// <summary>
 /// 计算文本显示宽、高
 /// </summary>
 /// <param name="text">The text.</param>
 /// <param name="fontFamily">The font family.</param>
 /// <param name="fontStyle">The font style.</param>
 /// <param name="fontWeight">The font weight.</param>
 /// <param name="fontStretch">The font stretch.</param>
 /// <param name="fontSize">Size of the font.</param>
 /// <returns></returns>
 public static MeasureSize MeasureTextSize(
     string text,
     System.Windows.Media.FontFamily fontFamily,
     System.Windows.FontStyle fontStyle,
     System.Windows.FontWeight fontWeight,
     System.Windows.FontStretch fontStretch,
     double fontSize)
 {
     System.Windows.Media.FormattedText ft = new System.Windows.Media.FormattedText(text,
                                                                                    System.Globalization.CultureInfo.CurrentCulture,
                                                                                    System.Windows.FlowDirection.LeftToRight,
                                                                                    new System.Windows.Media.Typeface(fontFamily, fontStyle, fontWeight, fontStretch),
                                                                                    fontSize,
                                                                                    System.Windows.Media.Brushes.Black);
     return(new MeasureSize(ft.Width, ft.Height));
 }
예제 #56
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="explorerTreeVM"></param>
        protected AExplorerTreeChildItemFontConfiguration(ExplorerTreeViewModel explorerTreeVM)
        {
            this.ExplorerTreeVM = explorerTreeVM;



            // don't use property for initialisation!!!
            // because property calls -> UpdateCurrentlyLoadedFontVMsOfTheExplorerTree()
            // and this uses ExplorerTreeVM -> and this could be null!!!!
            // I did not want a zero check, because for these no reasonable error
            // handling would be possible. Or would a log make sense here?
            this.fontFamily = new System.Windows.Media.FontFamily("Times New Roman");
            this.fontSize   = 12;
            this.fontStrech = FontStretches.Normal;
            this.fontStyle  = FontStyles.Normal;
            this.fontWeight = FontWeights.Normal;
        }
예제 #57
0
        public static FontStyle Convert(sw.FontStyle fontStyle, sw.FontWeight fontWeight)
        {
            var style = FontStyle.None;

            if (fontStyle == sw.FontStyles.Italic)
            {
                style |= FontStyle.Italic;
            }
            if (fontStyle == sw.FontStyles.Oblique)
            {
                style |= FontStyle.Italic;
            }
            if (fontWeight == sw.FontWeights.Bold)
            {
                style |= FontStyle.Bold;
            }
            return(style);
        }
        public Rect MeasureString(
            System.Windows.Media.DrawingContext graphics,
            System.Windows.Media.FontFamily fontFamily,
            System.Windows.FontStyle fontStyle,
            System.Windows.FontWeight fontWeight,
            double fontSize,
            string strText,
            System.Windows.Point ptDraw,
            System.Globalization.CultureInfo ci,
            ref double fStartX,
            ref double fStartY,
            ref double fDestWidth,
            ref double fDestHeight)
        {
            Geometry path = GDIPath.CreateTextGeometry(strText, fontFamily, fontStyle, fontWeight, fontSize, ptDraw, ci);

            Pen pen = new Pen(new SolidColorBrush(Color.FromArgb(255, 0, 0, 0)), m_nThickness1 + m_nThickness2);

            return(path.GetRenderBounds(pen));
        }
예제 #59
0
        public SubtitleParagraph()
        {
            _font     = (GetValue(FontProperty) as FontFamily);
            _fontSize = (double)(GetValue(FontSizeProperty));
            FontWeight weight = Bold ? FontWeights.Bold : FontWeights.Normal;
            FontStyle  style  = Italic ? FontStyles.Italic : FontStyles.Normal;

            _typeface = new Typeface(Font,
                                     style,
                                     weight,
                                     FontStretches.Normal);

            _typeface.TryGetGlyphTypeface(out _glyphTypeface);

            _newText   = new Semaphore(0, 1);
            _rendering = new Thread((ThreadStart)MakeBitmap);
            _rendering.IsBackground = true;
            _rendering.Priority     = ThreadPriority.BelowNormal;
            _rendering.Start();
        }
예제 #60
0
        //</SnippetOnRender>
        //<SnippetCreateText>
        /// <summary>
        /// Create the outline geometry based on the formatted text.
        /// </summary>
        public void CreateText()
        {
            System.Windows.FontStyle fontStyle = FontStyles.Normal;
            FontWeight fontWeight = FontWeights.Medium;

            if (Bold == true)
            {
                fontWeight = FontWeights.Bold;
            }
            if (ExtraBold == true)
            {
                fontWeight = FontWeights.ExtraBold;
            }
            if (Italic == true)
            {
                fontStyle = FontStyles.Italic;
            }

            // Create the formatted text based on the properties set.
            FormattedText formattedText = new FormattedText(
                Text,
                CultureInfo.CurrentCulture,
                FlowDirection.LeftToRight,
                new Typeface(
                    Font,
                    fontStyle,
                    fontWeight,
                    FontStretches.Normal),
                FontSize,
                System.Windows.Media.Brushes.Black // This brush does not matter since we use the geometry of the text.
                );

            // Build the geometry object that represents the text.
            _textGeometry = formattedText.BuildGeometry(new System.Windows.Point(0, 0));

            // Build the geometry object that represents the text highlight.
            if (Highlight == true)
            {
                _textHighLightGeometry = formattedText.BuildHighlightGeometry(new System.Windows.Point(0, 0));
            }
        }