当前位置: 首页>>代码示例>>C#>>正文


C# Windows.FontStretch类代码示例

本文整理汇总了C#中System.Windows.FontStretch的典型用法代码示例。如果您正苦于以下问题:C# FontStretch类的具体用法?C# FontStretch怎么用?C# FontStretch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FontStretch类属于System.Windows命名空间,在下文中一共展示了FontStretch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MeasureText

        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);
        }
开发者ID:LionFree,项目名称:Cush,代码行数:29,代码来源:MRUTextHelper.cs

示例2: SetStretch

 public object SetStretch(object handle, FontStretch stretch)
 {
     var font = (FontData)handle;
     font = font.Clone ();
     font.Stretch = DataConverter.ToWpfFontStretch (stretch);
     return font;
 }
开发者ID:joncham,项目名称:xwt,代码行数:7,代码来源:FontBackendHandler.cs

示例3: GraphicsText

        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();
        }
开发者ID:ritnorthstar,项目名称:Minimap-Control,代码行数:31,代码来源:GraphicsText.cs

示例4: WpfFontFamilyInfo

 public WpfFontFamilyInfo(FontFamily family, FontWeight weight, 
     FontStyle style, FontStretch stretch)
 {
     _family  = family;
     _weight  = weight;
     _style   = style;
     _stretch = stretch;
 }
开发者ID:udayanroy,项目名称:SvgSharp,代码行数:8,代码来源:WpfFontFamilyInfo.cs

示例5: ToFontAwesomeIcon

        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;
        }
开发者ID:run00,项目名称:GitToWork,代码行数:58,代码来源:ExtensionsForString.cs

示例6: Create

 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 ()
     };
 }
开发者ID:modulexcite,项目名称:xwt,代码行数:9,代码来源:FontBackendHandler.cs

示例7: Font

 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;
 }
开发者ID:catwalkagogo,项目名称:Heron,代码行数:9,代码来源:Font.cs

示例8: FontInfo

		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;
		}
开发者ID:tablesmit,项目名称:WpfColorFont,代码行数:9,代码来源:FontInfo.cs

示例9: GetScreenSize

        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);
        }
开发者ID:mmalek06,项目名称:FunkyCodeEditor,代码行数:9,代码来源:StringExtensions.cs

示例10: MeasureText

 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);
 }
开发者ID:WeiChou,项目名称:alphaTab,代码行数:10,代码来源:MeasureUtil.cs

示例11: Font

 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;
 }
开发者ID:guidgets,项目名称:XamlGrid,代码行数:10,代码来源:Font.cs

示例12: MatchingStyle

 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
         );
 }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:12,代码来源:MatchingStyle.cs

示例13: ConstructFaceNamesByStyleWeightStretch

        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;
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:12,代码来源:FontDifferentiator.cs

示例14: BuildFaceName

        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();
        }         
开发者ID:JianwenSun,项目名称:cc,代码行数:53,代码来源:FontDifferentiator.cs

示例15: ToWpfFontStretch

        public static SW.FontStretch ToWpfFontStretch(FontStretch value)
        {
            if (value == FontStretch.UltraCondensed) return SW.FontStretches.UltraCondensed;
            if (value == FontStretch.ExtraCondensed) return SW.FontStretches.ExtraCondensed;
            if (value == FontStretch.Condensed) return SW.FontStretches.Condensed;
            if (value == FontStretch.SemiCondensed) return SW.FontStretches.SemiCondensed;
            if (value == FontStretch.SemiExpanded) return SW.FontStretches.SemiExpanded;
            if (value == FontStretch.Expanded) return SW.FontStretches.Expanded;
            if (value == FontStretch.ExtraExpanded) return SW.FontStretches.ExtraExpanded;
            if (value == FontStretch.UltraExpanded) return SW.FontStretches.UltraExpanded;

            return SW.FontStretches.Normal;
        }
开发者ID:pixelmeister,项目名称:xwt,代码行数:13,代码来源:DataConverter.cs


注:本文中的System.Windows.FontStretch类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。