Exemple #1
0
 public static int ConvertToInt(FontStyle font)
 {
     if (font.Equals(FontStyles.Oblique))
     {
         return(1);
     }
     if (font.Equals(FontStyles.Italic))
     {
         return(2);
     }
     return(0);
 }
Exemple #2
0
        private void FontSelectForm_Load(object sender, EventArgs e)
        {
            cf = (ChildForm)MainForm.getChildForm();
            int indexSize;

            this.selectFont.Text = cf.Getfont().Name;
            this.sizeText.Text   = cf.Getfont().Size.ToString();
            shape = cf.Getfont().Style;
            if (shape.Equals(FontStyle.Regular))
            {
                this.shapeText.Text     = "常规";
                shapeList.SelectedIndex = 0;
            }
            else if (shape.Equals(FontStyle.Italic))
            {
                this.shapeText.Text     = "倾斜";
                shapeList.SelectedIndex = 1;
            }
            else if (shape.Equals(FontStyle.Bold))
            {
                this.shapeText.Text     = "粗体";
                shapeList.SelectedIndex = 2;
            }
            else if (shape.Equals(FontStyle.Bold | FontStyle.Italic))
            {
                this.shapeText.Text     = "粗体 倾斜";
                shapeList.SelectedIndex = 3;
            }
            foreach (System.Drawing.FontFamily i in objFont.Families)
            {
                this.fontList.Items.Add(i.Name.ToString());
            }

            this.fontList.SelectedIndex = this.fontList.FindString(this.selectFont.Text);
            indexSize = this.fontList.SelectedIndex - 3;
            if (indexSize < 0)
            {
                indexSize = 0;
            }
            this.fontList.TopIndex = indexSize;

            this.previewtext.Font = new System.Drawing.Font(cf.Getfont().Name, float.Parse(cf.Getfont().Size.ToString()), cf.Getfont().Style, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
        }
Exemple #3
0
        /// <summary>
        /// Determines whether the specified <see cref="System.Object"/> is equal to the current <see cref="Eto.Drawing.Font"/>.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object"/> to compare with the current <see cref="Eto.Drawing.Font"/>.</param>
        /// <returns><c>true</c> if the specified <see cref="System.Object"/> is equal to the current <see cref="Eto.Drawing.Font"/>;
        /// otherwise, <c>false</c>.</returns>
        public override bool Equals(object obj)
        {
            var font = obj as Font;

            return(font != null &&
                   object.ReferenceEquals(Platform, font.Platform) &&
                   Family.Equals(font.Family) &&
                   Size.Equals(font.Size) &&
                   FontStyle.Equals(font.FontStyle));
        }
        //---------------------------------------------------------------------------------------------
        public override bool Equals(object obj)
        {
            TypefaceStyle style = obj as TypefaceStyle;
            bool          check = false;

            if (FFontStyle.Equals(style.FontStyle) && (FFontStretch.Equals(style.FontStretch)) && (FFontWeight.Equals(style.FontWeight)))
            {
                check = true;
            }

            return(check);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public bool Equals(ExcelCellFontInfo other)
        {
            if (other == null) return false;

            if (!string.Equals(this.FontFamily, other.FontFamily)) return false;
            if (!double.Equals(this.FontSize, other.FontSize)) return false;
            if (!FontStyle.Equals(this.FontStyle, other.FontStyle)) return false;
            if (!System.Windows.FontWeight.Equals(this.FontWeight, other.FontWeight)) return false;
            if (!Color.Equals(this.FontColour, other.FontColour)) return false;
            if (!bool.Equals(this.FontUnderlined, other.FontUnderlined)) return false;

            return true;
        }
Exemple #6
0
        /// <summary>
        /// Returns true if Font instances are equal
        /// </summary>
        /// <param name="input">Instance of Font to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Font input)
        {
            if (input == null)
            {
                return(false);
            }

            return
                ((
                     FontStyle == input.FontStyle ||
                     FontStyle.Equals(input.FontStyle)
                     ) &&
                 (
                     FamilyName == input.FamilyName ||
                     (FamilyName != null &&
                      FamilyName.Equals(input.FamilyName))
                 ));
        }
Exemple #7
0
        /// <summary>
        /// Returns true if PdfAlignedTextParameters instances are equal
        /// </summary>
        /// <param name="input">Instance of PdfAlignedTextParameters to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(PdfAlignedTextParameters input)
        {
            if (input == null)
            {
                return(false);
            }

            return
                ((
                     TextVerticalAlignment == input.TextVerticalAlignment ||
                     TextVerticalAlignment.Equals(input.TextVerticalAlignment)
                     ) &&
                 (
                     TextHorizontalAlignment == input.TextHorizontalAlignment ||
                     TextHorizontalAlignment.Equals(input.TextHorizontalAlignment)
                 ) &&
                 (
                     Text == input.Text ||
                     (Text != null &&
                      Text.Equals(input.Text))
                 ) &&
                 (
                     TextColor == input.TextColor ||
                     (TextColor != null &&
                      TextColor.Equals(input.TextColor))
                 ) &&
                 (
                     FontName == input.FontName ||
                     (FontName != null &&
                      FontName.Equals(input.FontName))
                 ) &&
                 (
                     StandardFontName == input.StandardFontName ||
                     StandardFontName.Equals(input.StandardFontName)
                 ) &&
                 (
                     FontStyle == input.FontStyle ||
                     FontStyle.Equals(input.FontStyle)
                 ) &&
                 (
                     FontSize == input.FontSize ||
                     FontSize.Equals(input.FontSize)
                 ));
        }
Exemple #8
0
        protected WpfFontFamilyInfo GetTextFontFamilyInfo(SvgTextContentElement element)
        {
            _actualFontName = null;

            string fontFamily = element.GetPropertyValue("font-family");

            string[] fontNames = fontFamily.Split(new char[1] {
                ','
            });

            FontStyle   fontStyle   = GetTextFontStyle(element);
            FontWeight  fontWeight  = GetTextFontWeight(element);
            FontStretch fontStretch = GetTextFontStretch(element);

            var comparer   = StringComparison.OrdinalIgnoreCase;
            var docElement = element.OwnerDocument;

            ISet <string> svgFontFamilies = docElement.SvgFontFamilies;
            IDictionary <string, string> styledFontIds = docElement.StyledFontIds;

            IList <string> svgFontNames = null;

            if (svgFontFamilies != null && svgFontFamilies.Count != 0)
            {
                svgFontNames = new List <string>();
            }
            //var systemFontFamilies = Fonts.SystemFontFamilies;

            var wpfSettings         = _context.Settings;
            var fontFamilyNames     = wpfSettings.FontFamilyNames;
            var privateFontFamilies = wpfSettings.HasFontFamilies;

            FontFamily family = null;
            // using separate pointer to give less priority to generic font names
            FontFamily genericFamily = null;

            WpfFontFamilyType familyType = WpfFontFamilyType.None;

            foreach (string fn in fontNames)
            {
                try
                {
                    string fontName = fn.Trim(new char[] { ' ', '\'', '"' });
                    if (svgFontFamilies != null && svgFontFamilies.Count != 0)
                    {
                        if (svgFontFamilies.Contains(fontName))
                        {
                            svgFontNames.Add(fontName);
                            continue;
                        }
                        if (styledFontIds.ContainsKey(fontName))
                        {
                            string mappedFontName = styledFontIds[fontName];
                            if (svgFontFamilies.Contains(mappedFontName))
                            {
                                svgFontNames.Add(mappedFontName);
                                continue;
                            }
                        }
                    }

                    if (string.Equals(fontName, "serif", comparer))
                    {
                        genericFamily = WpfDrawingSettings.GenericSerif;
                    }
                    else if (string.Equals(fontName, "sans-serif", comparer) ||
                             string.Equals(fontName, "sans serif", comparer))
                    {
                        genericFamily = WpfDrawingSettings.GenericSansSerif;
                    }
                    else if (string.Equals(fontName, "monospace", comparer))
                    {
                        genericFamily = WpfDrawingSettings.GenericMonospace;
                    }
                    else if (styledFontIds.ContainsKey(fontName))
                    {
                        string mappedFontName = styledFontIds[fontName];
                        family = LookupFontFamily(mappedFontName, fontFamilyNames);
                        if (family != null)
                        {
                            _actualFontName = mappedFontName;
                            familyType      = WpfFontFamilyType.System;
                        }
                    }
                    else
                    {
                        // Try looking up fonts in the system font registry...
                        family = LookupFontFamily(fontName, fontFamilyNames);
                        if (family != null)
                        {
                            _actualFontName = fontName;
                            familyType      = WpfFontFamilyType.System;
                        }

                        // If not found, look through private fonts if available..
                        if (family == null && privateFontFamilies)
                        {
                            family = wpfSettings.LookupFontFamily(fontName);
                            if (family != null)
                            {
                                _actualFontName = fontName;
                                familyType      = WpfFontFamilyType.Private;
                            }
                        }
                    }

                    if (family != null)
                    {
                        return(new WpfFontFamilyInfo(familyType, _actualFontName, family,
                                                     fontWeight, fontStyle, fontStretch));
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceError(ex.ToString());
                }
            }

            // If set, use the SVG-Font...
            if (svgFontNames != null && svgFontNames.Count != 0)
            {
                FontFamily altFamily = (genericFamily != null) ? genericFamily : WpfDrawingSettings.DefaultFontFamily;

                IList <SvgFontElement> svgFonts = docElement.GetFonts(svgFontNames);
                if (svgFonts != null && svgFonts.Count != 0)
                {
                    string fontVariant = element.GetPropertyValue("font-variant");

                    // For a single match...
                    if (svgFonts.Count == 1)
                    {
                        var fontFamilyInfo = new WpfFontFamilyInfo(svgFonts[0].FontFamily, svgFonts[0],
                                                                   fontWeight, fontStyle, fontStretch);

                        fontFamilyInfo.Variant = fontVariant;
                        // For rendering that do not support the SVG Fonts...
                        fontFamilyInfo.Family = altFamily;
                        return(fontFamilyInfo);
                    }

                    // For the defined font style...
                    if (fontStyle != FontStyles.Normal)
                    {
                        // Then it is either oblique or italic
                        SvgFontElement closeFont   = null;
                        SvgFontElement closestFont = null;
                        bool           isItalic    = fontStyle.Equals(FontStyles.Italic);
                        foreach (var svgFont in svgFonts)
                        {
                            var fontFace = svgFont.FontFace;
                            if (fontFace == null)
                            {
                                continue;
                            }
                            var typefaceStyle = GetTextFontStyle(fontFace.FontStyle);
                            if (fontStyle.Equals(typefaceStyle))
                            {
                                closeFont = svgFont;
                                if (closestFont == null)
                                {
                                    closestFont = svgFont;
                                }
                                var typefaceWeight = GetTextFontWeight(fontFace.FontWeight);
                                if (fontVariant.Equals(fontFace.FontVariant, comparer))
                                {
                                    closestFont = svgFont;
                                    if (fontWeight.Equals(typefaceWeight))
                                    {
                                        var fontFamilyInfo = new WpfFontFamilyInfo(svgFont.FontFamily, svgFont,
                                                                                   fontWeight, fontStyle, fontStretch);

                                        fontFamilyInfo.Variant = fontVariant;
                                        // For rendering that do not support the SVG Fonts...
                                        fontFamilyInfo.Family = altFamily;
                                        return(fontFamilyInfo);
                                    }
                                }
                            }
                            if (closeFont == null)
                            {
                                if (isItalic && typefaceStyle == FontStyles.Oblique)
                                {
                                    closeFont = svgFont;
                                }
                                if (!isItalic && typefaceStyle == FontStyles.Italic)
                                {
                                    closeFont = svgFont;
                                }
                            }
                        }
                        if (closestFont != null)
                        {
                            closeFont = closestFont;
                        }

                        if (closeFont != null)
                        {
                            var fontFamilyInfo = new WpfFontFamilyInfo(closeFont.FontFamily, closeFont,
                                                                       fontWeight, fontStyle, fontStretch);

                            fontFamilyInfo.Variant = fontVariant;
                            // For rendering that do not support the SVG Fonts...
                            fontFamilyInfo.Family = altFamily;
                            return(fontFamilyInfo);
                        }
                    }

                    SvgFontElement variantFont = null;
                    // For multiple matches, we will test the variants...
                    if (!string.IsNullOrWhiteSpace(fontVariant))
                    {
                        foreach (var svgFont in svgFonts)
                        {
                            var fontFace = svgFont.FontFace;
                            if (fontFace == null)
                            {
                                continue;
                            }
                            if (fontVariant.Equals(fontFace.FontVariant, comparer))
                            {
                                variantFont = svgFont;
                                // Check for more perfect match...
                                var typefaceWeight = GetTextFontWeight(fontFace.FontWeight);
                                var typefaceStyle  = GetTextFontStyle(fontFace.FontStyle);
                                if (fontStyle.Equals(typefaceStyle) && fontWeight.Equals(typefaceWeight))
                                {
                                    var fontFamilyInfo = new WpfFontFamilyInfo(svgFont.FontFamily, svgFont,
                                                                               fontWeight, fontStyle, fontStretch);

                                    fontFamilyInfo.Variant = fontVariant;
                                    // For rendering that do not support the SVG Fonts...
                                    fontFamilyInfo.Family = altFamily;
                                    return(fontFamilyInfo);
                                }
                            }
                        }

                        //if (variantFont != null)
                        //{
                        //    // If there was a matching variant but either style or weight not matched...
                        //    var fontFamilyInfo = new WpfFontFamilyInfo(variantFont.FontFamily, variantFont,
                        //        fontWeight, fontStyle, fontStretch);

                        //    fontFamilyInfo.Variant = fontVariant;
                        //    // For rendering that do not support the SVG Fonts...
                        //    fontFamilyInfo.Family = altFamily;
                        //    return fontFamilyInfo;
                        //}
                    }

                    // For the defined font weights...
                    if (fontWeight != FontWeights.Normal && fontWeight != FontWeights.Regular)
                    {
                        int            weightValue    = fontWeight.ToOpenTypeWeight();
                        int            selectedValue  = int.MaxValue;
                        SvgFontElement sameWeightFont = null;
                        SvgFontElement closestFont    = null;
                        foreach (var svgFont in svgFonts)
                        {
                            var fontFace = svgFont.FontFace;
                            if (fontFace == null)
                            {
                                continue;
                            }
                            var typefaceWeight = GetTextFontWeight(fontFace.FontWeight);
                            if (fontWeight.Equals(typefaceWeight))
                            {
                                sameWeightFont = svgFont;
                                var typefaceStyle = GetTextFontStyle(fontFace.FontStyle);
                                if (fontStyle.Equals(typefaceStyle))
                                {
                                    var fontFamilyInfo = new WpfFontFamilyInfo(svgFont.FontFamily, svgFont,
                                                                               fontWeight, fontStyle, fontStretch);

                                    fontFamilyInfo.Variant = fontVariant;
                                    // For rendering that do not support the SVG Fonts...
                                    fontFamilyInfo.Family = altFamily;
                                    return(fontFamilyInfo);
                                }
                            }

                            int weightDiff = Math.Abs(weightValue - typefaceWeight.ToOpenTypeWeight());
                            if (weightDiff < selectedValue)
                            {
                                closestFont   = svgFont;
                                selectedValue = weightDiff;
                            }
                        }

                        // If the weights matched, but not the style
                        if (sameWeightFont != null)
                        {
                            var fontFamilyInfo = new WpfFontFamilyInfo(sameWeightFont.FontFamily, sameWeightFont,
                                                                       fontWeight, fontStyle, fontStretch);

                            fontFamilyInfo.Variant = fontVariant;
                            // For rendering that do not support the SVG Fonts...
                            fontFamilyInfo.Family = altFamily;
                            return(fontFamilyInfo);
                        }
                        if (closestFont != null)
                        {
                            var fontFamilyInfo = new WpfFontFamilyInfo(closestFont.FontFamily, closestFont,
                                                                       fontWeight, fontStyle, fontStretch);

                            fontFamilyInfo.Variant = fontVariant;
                            // For rendering that do not support the SVG Fonts...
                            fontFamilyInfo.Family = altFamily;
                            return(fontFamilyInfo);
                        }
                    }

                    if (variantFont != null)
                    {
                        // If there was a matching variant but either style or weight not matched...
                        var fontFamilyInfo = new WpfFontFamilyInfo(variantFont.FontFamily, variantFont,
                                                                   fontWeight, fontStyle, fontStretch);

                        fontFamilyInfo.Variant = fontVariant;
                        // For rendering that do not support the SVG Fonts...
                        fontFamilyInfo.Family = altFamily;
                        return(fontFamilyInfo);
                    }
                    else // If the variant is not found, return the first match...
                    {
                        var fontFamilyInfo = new WpfFontFamilyInfo(svgFonts[0].FontFamily, svgFonts[0],
                                                                   fontWeight, fontStyle, fontStretch);

                        fontFamilyInfo.Variant = fontVariant;
                        // For rendering that do not support the SVG Fonts...
                        fontFamilyInfo.Family = altFamily;
                        return(fontFamilyInfo);
                    }

                    //// For multiple matches, we will test the variants...
                    //if (string.IsNullOrWhiteSpace(fontVariant))
                    //{
                    //    // Not found, return the first match...
                    //    var fontFamilyInfo = new WpfFontFamilyInfo(svgFonts[0].FontFamily, svgFonts[0],
                    //        fontWeight, fontStyle, fontStretch);

                    //    fontFamilyInfo.Variant = fontVariant;
                    //    // For rendering that do not support the SVG Fonts...
                    //    fontFamilyInfo.Family = altFamily;
                    //    return fontFamilyInfo;
                    //}
                }
            }

            if (genericFamily != null)
            {
                return(new WpfFontFamilyInfo(WpfFontFamilyType.Generic, _actualFontName, genericFamily,
                                             fontWeight, fontStyle, fontStretch));
            }

            // No known font-family was found => default to "Arial"
            return(new WpfFontFamilyInfo(familyType, _actualFontName,
                                         WpfDrawingSettings.DefaultFontFamily, fontWeight, fontStyle, fontStretch));
        }
        private FontFamily GetMatchingFontFamily(IList <FontFamily> fontFamilies,
                                                 FontWeight weight, FontStyle style, FontStretch stretch)
        {
            if (fontFamilies == null || fontFamilies.Count == 0)
            {
                return(null);
            }
            // For a single match...
            if (fontFamilies.Count == 1)
            {
                return(fontFamilies[0]);
            }

            // 1. Look for a possibility of all properties matching
            foreach (FontFamily fontFamily in fontFamilies)
            {
                // Return the family typeface collection for the font family.
                FamilyTypefaceCollection familyTypefaces = fontFamily.FamilyTypefaces;

                // Enumerate the family typefaces in the collection.
                foreach (FamilyTypeface typeface in familyTypefaces)
                {
                    FontStyle   fontStyle   = typeface.Style;
                    FontWeight  fontWeight  = typeface.Weight;
                    FontStretch fontStretch = typeface.Stretch;

                    if (fontStyle.Equals(style) && fontWeight.Equals(weight) && fontStretch.Equals(stretch))
                    {
                        return(fontFamily);
                    }
                }
            }

            // For the defined font style...
            if (style != FontStyles.Normal)
            {
                // Then it is either oblique or italic
                FontFamily closeFamily   = null;
                FontFamily closestFamily = null;
                bool       isItalic      = style.Equals(FontStyles.Italic);

                foreach (FontFamily fontFamily in fontFamilies)
                {
                    // Return the family typeface collection for the font family.
                    FamilyTypefaceCollection familyTypefaces = fontFamily.FamilyTypefaces;

                    // Enumerate the family typefaces in the collection.
                    foreach (FamilyTypeface typeface in familyTypefaces)
                    {
                        FontStyle   fontStyle   = typeface.Style;
                        FontWeight  fontWeight  = typeface.Weight;
                        FontStretch fontStretch = typeface.Stretch;

                        if (fontStyle.Equals(style))
                        {
                            closeFamily = fontFamily;
                            if (closestFamily == null)
                            {
                                closestFamily = fontFamily;
                            }
                            if (fontStretch.Equals(stretch))
                            {
                                closestFamily = fontFamily;
                                if (fontWeight.Equals(weight))
                                {
                                    return(fontFamily);
                                }
                            }
                        }
                        if (closeFamily == null)
                        {
                            if (isItalic && fontStyle == FontStyles.Oblique)
                            {
                                closeFamily = fontFamily;
                            }
                            if (!isItalic && fontStyle == FontStyles.Italic)
                            {
                                closeFamily = fontFamily;
                            }
                        }
                    }
                    if (closestFamily != null)
                    {
                        closeFamily = closestFamily;
                    }

                    if (closeFamily != null)
                    {
                        return(closeFamily);
                    }
                }
            }

            // For the defined font weights...
            if (weight != FontWeights.Normal && weight != FontWeights.Regular)
            {
                int        weightValue      = weight.ToOpenTypeWeight();
                int        selectedValue    = int.MaxValue;
                FontFamily sameWeightFamily = null;
                FontFamily closestFamily    = null;
                foreach (FontFamily fontFamily in fontFamilies)
                {
                    // Return the family typeface collection for the font family.
                    FamilyTypefaceCollection familyTypefaces = fontFamily.FamilyTypefaces;

                    // Enumerate the family typefaces in the collection.
                    foreach (FamilyTypeface typeface in familyTypefaces)
                    {
                        FontStyle   fontStyle   = typeface.Style;
                        FontWeight  fontWeight  = typeface.Weight;
                        FontStretch fontStretch = typeface.Stretch;

                        if (fontWeight.Equals(weight))
                        {
                            sameWeightFamily = fontFamily;
                            if (fontStyle.Equals(style))
                            {
                                return(fontFamily);
                            }
                        }

                        int weightDiff = Math.Abs(weightValue - fontWeight.ToOpenTypeWeight());
                        if (weightDiff < selectedValue)
                        {
                            closestFamily = fontFamily;
                            selectedValue = weightDiff;
                        }

                        // If the weights matched, but not the style
                        if (sameWeightFamily != null)
                        {
                            return(sameWeightFamily);
                        }
                        if (closestFamily != null)
                        {
                            return(closestFamily);
                        }
                    }
                }
            }

            return(null);
        }
Exemple #10
0
 public bool ShouldSerializeFontStyle() =>
 SerializeDefaults ||
 !FontStyle.Equals(ZPLForgeDefaults.Elements.Text.FontStyle);