/// <summary>
                /// Updates the position of the right character.
                /// </summary>
                private float UpdateCharOffset(Line line, int right, int left, Vector2 pos, float xAlign)
                {
                    char           ch             = line.Chars[right];
                    FormattedGlyph formattedGlyph = line.FormattedGlyphs[right];
                    IFontStyle     fontStyle      = FontManager.GetFontStyle(formattedGlyph.format.StyleIndex);

                    float textSize    = formattedGlyph.format.TextSize,
                          formatScale = textSize * fontStyle.FontScale,
                    // Quick fix for CJK characters in Space Engineers font data
                          cjkOffset = (formattedGlyph.format.StyleIndex.X == 0 && ch >= 0x4E00) ? (-4f * textSize) : 0f;

                    // Kerning adjustment
                    if (left >= 0)
                    {
                        GlyphFormat leftFmt = line.FormattedGlyphs[left].format, rightFmt = formattedGlyph.format;

                        if (leftFmt.StyleIndex == rightFmt.StyleIndex && leftFmt.TextSize == rightFmt.TextSize)
                        {
                            pos.X += fontStyle.GetKerningAdjustment(line.Chars[left], ch) * formatScale;
                        }
                    }

                    GlyphLocData locData = line.LocData[right];

                    line.SetOffsetAt(right, new Vector2()
                    {
                        X = pos.X + locData.bbSize.X * .5f + (formattedGlyph.glyph.leftSideBearing * formatScale) + xAlign,
                        Y = pos.Y - (locData.bbSize.Y * .5f) + (fontStyle.BaseLine * formatScale) + cjkOffset
                    });

                    return(pos.X + locData.chSize.X);
                }
Пример #2
0
 public BadgeBase(BadgeQueryData d, ILanguage language)
 {
     BadgeQueryData    = d;
     _language         = language;
     _defaultFontStyle = d.FontStyle;
     _sections         = new Section[] { };
 }
        public static IFontStyle GetStyleWithWeightNearestTo(
            this IFontFamily family,
            int weight,
            FontStyleType type = FontStyleType.Normal)
        {
            if (family == null)
            {
                return(null);
            }

            IFontStyle closest           = null;
            var        closestDifference = int.MaxValue;

            foreach (var font in family.GetFontStyles())
            {
                if (font.StyleType == type)
                {
                    var difference = Math.Abs(font.Weight - weight);
                    if (difference == 0)
                    {
                        return(font);
                    }

                    if (difference < closestDifference)
                    {
                        closest           = font;
                        closestDifference = difference;
                    }
                }
            }

            return(closest);
        }
Пример #4
0
                    /// <summary>
                    /// Sets the formatting for the given range of characters in the line
                    /// </summary>
                    public void SetFormatting(int start, int end, GlyphFormat format, bool onlyChangeColor)
                    {
                        Vector4 bbColor = QuadBoard.GetQuadBoardColor(format.Data.Item4);

                        for (int n = start; n <= end; n++)
                        {
                            if (onlyChangeColor)
                            {
                                var quadBoard = glyphBoards[n];
                                quadBoard.bbColor = bbColor;

                                glyphBoards[n]     = quadBoard;
                                formattedGlyphs[n] = new FormattedGlyph(formattedGlyphs[n].glyph, format);
                            }
                            else if (!formattedGlyphs[n].format.Equals(format))
                            {
                                IFontStyle fontStyle = FontManager.GetFontStyle(format.Data.Item3);
                                float      scale     = format.Data.Item2 * fontStyle.FontScale;
                                Glyph      glyph     = fontStyle[chars[n]];
                                Vector2    glyphSize = new Vector2(glyph.advanceWidth, fontStyle.Height) * scale;

                                formattedGlyphs[n] = new FormattedGlyph(glyph, format);
                                locData[n]         = new GlyphLocData(glyph.MatFrame.Material.size * scale, glyphSize);
                                glyphBoards[n]     = glyph.GetQuadBoard(format, bbColor);
                            }
                        }
                    }
Пример #5
0
 /// <summary>
 /// Clones font style.
 /// </summary>
 /// <param name="fontStyle">The font style to clone.</param>
 /// <returns>The new instance of the <see cref="FontStyle"/> class.</returns>
 public static IFontStyle Clone(this IFontStyle fontStyle)
 {
     return(new FontStyle()
     {
         Flags = fontStyle.Flags
     });
 }
Пример #6
0
 public BadgeStyle(IFontStyle defaultFontStyle, ISectionStyle defaultTextSectionStyle, IBadgeGeometry geometry,
                   double shadowRight, double shadowBottom)
 {
     DefaultFontStyle        = defaultFontStyle;
     DefaultTextSectionStyle = defaultTextSectionStyle;
     BadgeGeometry           = geometry;
     ShadowRight             = shadowRight;
     ShadowBottom            = shadowBottom;
 }
Пример #7
0
        public BadgeQueryData(HttpRequest r)
        {
            var q = r.QueryString;

            User      = q["user"] ?? "user";
            Repo      = q["repo"] ?? "repo";
            Theme     = q["theme"] ?? "dark";
            Size      = q["badgeSize"] ?? "medium";
            Icon      = bool.Parse(q["icon"] ?? "true");
            FontStyle = q.GetFontStyle(Theme);
        }
        public int CompareTo(IFontStyle other)
        {
            if (Name.Equals("Regular") || Name.Equals("Plain") || Name.Equals("Normal"))
            {
                return(-1);
            }
            else if (other.Name.Equals("Regular") || other.Name.Equals("Plain") || other.Name.Equals("Normal"))
            {
                return(1);
            }

            return(String.Compare(Name, other.Name, StringComparison.Ordinal));
        }
        public static void SetFontsFromAttributes(this IFontStyle hasStyle, Dictionary <string, object> additionalAttributes)
        {
            if (additionalAttributes != null)
            {
                hasStyle.Font.Bold      = additionalAttributes.GetValue("Font-Bold", bool.Parse, hasStyle.Font.Bold);
                hasStyle.Font.Italic    = additionalAttributes.GetValue("Font-Italic", bool.Parse, hasStyle.Font.Italic);
                hasStyle.Font.Underline = additionalAttributes.GetValue("Font-Underline", bool.Parse, hasStyle.Font.Underline);

                hasStyle.Font.Names     = additionalAttributes.GetValue("Font-Names", a => a, hasStyle.Font.Names);
                hasStyle.Font.Overline  = additionalAttributes.GetValue("Font-Overline", bool.Parse, hasStyle.Font.Overline);
                hasStyle.Font.Size      = additionalAttributes.GetValue("Font-Size", FontUnit.Parse, hasStyle.Font.Size);
                hasStyle.Font.Strikeout = additionalAttributes.GetValue("Font-Strikeout", bool.Parse, hasStyle.Font.Strikeout);
            }
        }
Пример #10
0
                    /// <summary>
                    /// Inserts a new character at the index specified with the given format
                    /// </summary>
                    public void InsertNew(int index, char ch, GlyphFormat format, Vector4 color)
                    {
                        IFontStyle fontStyle = FontManager.GetFontStyle(format.StyleIndex);
                        float      scale     = format.Data.Item2 * fontStyle.FontScale;
                        Glyph      glyph     = fontStyle[ch];
                        Vector2    glyphSize = new Vector2(glyph.advanceWidth, fontStyle.Height) * scale;

                        chars.Insert(index, ch);
                        formattedGlyphs.Insert(index, new FormattedGlyph(glyph, format));
                        locData.Insert(index, new GlyphLocData(glyph.MatFrame.Material.size * scale, glyphSize));
                        glyphBoards.Insert(index, glyph.GetQuadBoard(format, color));

                        TrimExcess();
                    }
Пример #11
0
                    /// <summary>
                    /// Recalculates the width and height of the line.
                    /// </summary>
                    public void UpdateSize()
                    {
                        _size = Vector2.Zero;

                        if (chars.Count > 0)
                        {
                            for (int n = 0; n < locData.Count; n++)
                            {
                                GlyphLocData sizeData = locData[n];

                                if (sizeData.chSize.Y > _size.Y)
                                {
                                    _size.Y = sizeData.chSize.Y;
                                }

                                float chWidth = sizeData.chSize.X;

                                if (chars[n] == '\t')
                                {
                                    FormattedGlyph formattedGlyph = formattedGlyphs[n];
                                    IFontStyle     fontStyle      = FontManager.GetFontStyle(formattedGlyph.format.StyleIndex);
                                    float          scale          = formattedGlyph.format.TextSize * fontStyle.FontScale;

                                    chWidth = formattedGlyphs[n].glyph.advanceWidth * scale;
                                    float rem = _size.X % chWidth;

                                    if (rem < chWidth * .8f)
                                    {
                                        chWidth -= rem;
                                    }
                                    else // if it's really close, just skip to the next stop
                                    {
                                        chWidth += (chWidth - rem);
                                    }

                                    sizeData.chSize.X = chWidth;
                                    sizeData.bbSize.X = chWidth;

                                    locData[n] = sizeData;
                                }

                                _size.X += chWidth;
                            }
                        }
                    }
                /// <summary>
                /// Calculates the baseline to be shared by each character in the line.
                /// </summary>
                private float GetBaseline(int line)
                {
                    float baseline = 0f;

                    for (int ch = 0; ch < lines[line].Count; ch++)
                    {
                        if (lines[line].LocData[ch].chSize.Y == lines[line].UnscaledSize.Y)
                        {
                            GlyphFormat format    = lines[line].FormattedGlyphs[ch].format;
                            IFontStyle  fontStyle = FontManager.Fonts[format.StyleIndex.X][format.StyleIndex.Y];

                            baseline = (fontStyle.BaseLine - (fontStyle.Height - fontStyle.BaseLine) * .5f) * (format.TextSize * fontStyle.FontScale);
                            break;
                        }
                    }

                    return(baseline);
                }
        public static string GetSvgStyle(this IFontStyle style)
        {
            if (style == null)
            {
                return(null);
            }

            if (style.StyleType == FontStyleType.Italic)
            {
                return("italic");
            }

            if (style.StyleType == FontStyleType.Oblique)
            {
                return("oblique");
            }

            return("normal");
        }
Пример #14
0
        public int CompareTo(IFontStyle other)
        {
            if (other == null)
            {
                return(-1);
            }

            if (_name.Equals("Regular") || _name.Equals("Plain") || _name.Equals("Normal"))
            {
                return(-1);
            }

            if (other.Name.Equals("Regular") || other.Name.Equals("Plain") || other.Name.Equals("Normal"))
            {
                return(1);
            }

            return(string.Compare(_name, other.Name, StringComparison.Ordinal));
        }
Пример #15
0
        public virtual IFontStyle GetDefaultFontStyle()
        {
            if (_defaultFontStyle == null)
            {
                if (_buildingDefaultStyle)
                {
                    return(null);
                }

                _buildingDefaultStyle = true;
                _defaultFontStyle     = GetFontStyleById(_defaultFontStyleName);

                if (_defaultFontStyle == null && !string.IsNullOrEmpty(_secondaryFontStyleName))
                {
                    _defaultFontStyle = GetFontStyleById(_secondaryFontStyleName);
                }

                if (_defaultFontStyle == null && !string.IsNullOrEmpty(_tertiaryFontStyleName))
                {
                    _defaultFontStyle = GetFontStyleById(_tertiaryFontStyleName);
                }

                if (_defaultFontStyle == null)
                {
                    var families = GetFontFamilies();
                    if (families != null && families.Length > 0)
                    {
                        _defaultFontStyle = families[0].GetFontStyles()[0];
                    }
                }

                _buildingDefaultStyle = false;
            }

            return(_defaultFontStyle);
        }
        public static string GetSvgWeight(this IFontStyle style)
        {
            if (style == null)
            {
                return(null);
            }

            if (style.Weight == FontUtils.Normal)
            {
                return("normal");
            }

            if (style.Weight == FontUtils.Regular)
            {
                return("normal");
            }

            if (style.Weight == FontUtils.Bold)
            {
                return("bold");
            }

            return(style.Weight.ToInvariantString());
        }
Пример #17
0
 public SectionStyle(IFontStyle fontStyle, string backgroundColor)
 {
     FontStyle       = fontStyle;
     BackgroundColor = backgroundColor;
 }
Пример #18
0
 //step 2:Set the concrete call called by the client to the
 //interface object defined in the step 1
 public FontStyleContext(IFontStyle IFontStyle)
 {
     this._IFontStyle = IFontStyle;
 }