コード例 #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
ファイル: FontInfo.cs プロジェクト: EmptyKeys/UI_Generator
 /// <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
ファイル: FontBackendHandler.cs プロジェクト: joncham/xwt
 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
ファイル: MRUTextHelper.cs プロジェクト: LionFree/Cush
        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
ファイル: TextElement.cs プロジェクト: xusongsong/DynamoRevit
        /// <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
ファイル: DataConverter.cs プロジェクト: pixelmeister/xwt
        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
ファイル: Font.cs プロジェクト: mlnlover11/IExtendFramework
 public Font()
 {
     Weight = FontWeights.Normal;
     Family = Fonts.SystemFontFamilies.ToArray<FontFamily>()[0];
     Size = 15;
     Stretch = FontStretches.Normal;
     Style = FontStyles.Normal;
 }
コード例 #20
0
 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;
 }
コード例 #22
0
 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;
 }
コード例 #24
0
 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;
 }
コード例 #25
0
 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
ファイル: Form1.cs プロジェクト: samgonzalezr/WPFSamples
 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
ファイル: FontInfo.cs プロジェクト: tablesmit/WpfColorFont
		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
ファイル: Form1.cs プロジェクト: ClemensT/WPF-Samples
 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
ファイル: FontBackendHandler.cs プロジェクト: modulexcite/xwt
 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
ファイル: CanvasHelper.cs プロジェクト: shaovoon/outline-text
 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");
 }
コード例 #36
0
 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
ファイル: MeasureUtil.cs プロジェクト: WeiChou/alphaTab
 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
ファイル: FontImage.cs プロジェクト: wqd1019dqw/Alex
        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
ファイル: SvgElementExtensions.cs プロジェクト: Ref12/Grazor
 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
ファイル: TrayIconRenderer.cs プロジェクト: qzcw/nbfc
 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();
 }
コード例 #43
0
        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
ファイル: FontDifferentiator.cs プロジェクト: JianwenSun/cc
        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
ファイル: FontDifferentiator.cs プロジェクト: JianwenSun/cc
        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;
 }
コード例 #48
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
ファイル: FontHelper.cs プロジェクト: GerHobbelt/PDFsharp
        /// <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
ファイル: DataConverter.cs プロジェクト: joncham/xwt
        //
        // 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
ファイル: FontImage.cs プロジェクト: Wolfthorn/Orchestra
        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
ファイル: Conversions.cs プロジェクト: CheckTech/Eto
        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);
        }
コード例 #58
0
        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));
            }
        }