コード例 #1
0
ファイル: SVGFont.cs プロジェクト: zigaosolin/SharpMedia
 internal SVGFontProvider(string name, SortedList <string, SVGGlyph> glyph,
                          SortedList <ComparablePair <char, char>, float> kernelling, SVGGlyph defaultGlyph)
 {
     this.name         = name;
     this.glyphs       = glyph;
     this.kernelling   = kernelling;
     this.defaultGlyph = defaultGlyph;
 }
コード例 #2
0
ファイル: SVGImport.cs プロジェクト: zigaosolin/SharpMedia
        public SVGFontProvider ImportSVG(XmlDocument document)
        {
            XmlNode font = document["svg"]["defs"]["font"];

            if (font == null)
            {
                throw new ArgumentException("The document does not include any fonts.");
            }

            // We write basic properties (for normalization).
            string name = font["font-face"]["font-family"] != null ? font["font-face"]["font-family"].InnerText : "unknown";

            // We extract data.
            if (font.Attributes["horiz-origin-x"] != null)
            {
                horizOriginX = int.Parse(font.Attributes["horiz-origin-x"].InnerText);
            }
            if (font.Attributes["horiz-origin-y"] != null)
            {
                horizOriginY = int.Parse(font.Attributes["horiz-origin-y"].InnerText);
            }

            if (horizOriginX != 0 || horizOriginY != 0)
            {
                throw new NotSupportedException();
            }

            if (font.Attributes["horiz-adv-x"] != null)
            {
                horizAdvX = int.Parse(font.Attributes["horiz-adv-x"].InnerText);
            }

            // We now extract glyphs.

            // TODO: extract missing gylph.

            SVGGlyph def = ProcessDefGlyph(font["missing-glyph"]);

            // Extract each glyph.
            foreach (XmlNode node in font)
            {
                if (node.Name == "glyph")
                {
                    ProcessGlyph(node);
                }
            }



            // We now rescale each glyph to range in y to [0,1].
            float      scale  = 1.0f / maxDimensions.Y;
            Matrix3x3f matrix = Matrix3x3f.CreateScale(new Vector3f(scale, scale, scale));

            foreach (KeyValuePair <string, SVGGlyph> pair in glyphs)
            {
                // We scale outline.
                pair.Value.Outline.Transform(matrix);
                pair.Value.Advance *= scale;
            }

            // Transform default.
            def.Advance *= scale;
            def.Outline.Transform(matrix);

            ImportKernellings(font);

            SortedList <ComparablePair <char, char>, float> r = new SortedList <ComparablePair <char, char>, float>();

            // We normalize kernellig (also negatie, since the + meaning is shrink in SVG, in our format,
            // it is enlarge).
            for (int z = 0; z < kernelling.Count; z++)
            {
                r.Add(kernelling.Keys[z], kernelling.Values[z] * -scale);
            }

            return(new SVGFontProvider(name, glyphs, r, def));
        }