Esempio n. 1
0
        private void ParseTextStyleMappings()
        {
            this.parsedTextStyles = new Dictionary <string, CharFont[]>();

            var textStyleMappings = rootElement.Element("TextStyleMappings");

            if (textStyleMappings == null)
            {
                throw new InvalidOperationException("Cannot find TextStyleMappings element.");
            }

            foreach (var mappingElement in textStyleMappings.Elements("TextStyleMapping"))
            {
                var textStyleName = mappingElement.AttributeValue("name");
                var charFonts     = new CharFont[3];
                foreach (var mapRangeElement in mappingElement.Elements("MapRange"))
                {
                    var fontId      = mapRangeElement.AttributeInt32Value("fontId");
                    var character   = mapRangeElement.AttributeInt32Value("start");
                    var code        = mapRangeElement.AttributeValue("code");
                    var codeMapping = rangeTypeMappings[code];

                    charFonts[(int)codeMapping] = new CharFont((char)character, fontId);
                }
                this.parsedTextStyles.Add(textStyleName, charFonts);
            }
        }
Esempio n. 2
0
        public Result <CharInfo> GetCharInfo(CharFont charFont, TexStyle style)
        {
            var size     = GetSizeFactor(style);
            var fontInfo = fontInfoList[charFont.FontId];
            var metrics  = GetMetrics(charFont, size);

            return(metrics.Map(m => new CharInfo(charFont.Character, fontInfo.Font, size, charFont.FontId, m)));
        }
Esempio n. 3
0
        public double GetSkew(CharFont charFont, TexStyle style)
        {
            var  fontInfo = fontInfoList[charFont.FontId];
            char skewChar = fontInfo.SkewCharacter;

            if (skewChar == 1)
            {
                return(0);
            }
            return(GetKern(charFont, new CharFont(skewChar, charFont.FontId), style));
        }
Esempio n. 4
0
        public CharFont GetLigature(CharFont leftCharFont, CharFont rightCharFont)
        {
            if (leftCharFont.FontId != rightCharFont.FontId)
            {
                return(null);
            }

            var fontInfo = fontInfoList[leftCharFont.FontId];

            return(fontInfo.GetLigature(leftCharFont.Character, rightCharFont.Character));
        }
Esempio n. 5
0
        private static Result <TexFontMetrics> GetMetrics(CharFont charFont, double size)
        {
            var fontInfo = fontInfoList[charFont.FontId];
            var metrics  = fontInfo.GetMetrics(charFont.Character);

            return(metrics.Map(m => new TexFontMetrics(
                                   m[TexFontUtilities.MetricsWidth],
                                   m[TexFontUtilities.MetricsHeight],
                                   m[TexFontUtilities.MetricsDepth],
                                   m[TexFontUtilities.MetricsItalic],
                                   size * TexFontUtilities.PixelsPerPoint)));
        }
Esempio n. 6
0
        public double GetKern(CharFont leftCharFont, CharFont rightCharFont, TexStyle style)
        {
            if (leftCharFont.FontId != rightCharFont.FontId)
            {
                return(0);
            }

            var fontInfo = fontInfoList[leftCharFont.FontId];

            return(fontInfo.GetKern(leftCharFont.Character, rightCharFont.Character,
                                    GetSizeFactor(style) * TexFontUtilities.PixelsPerPoint));
        }
Esempio n. 7
0
 public double GetSkew(CharFont charFont, TexStyle style) => throw MethodNotSupported(nameof(GetSkew));
Esempio n. 8
0
 public double GetKern(CharFont leftChar, CharFont rightChar, TexStyle style) => 0.0;
Esempio n. 9
0
 public Result <CharInfo> GetCharInfo(CharFont charFont, TexStyle style) =>
 Result.Error <CharInfo>(MethodNotSupported(nameof(this.GetCharInfo)));
Esempio n. 10
0
 public CharFont GetLigature(CharFont leftChar, CharFont rightChar) => null;