コード例 #1
0
        public static Strike Read(BinaryReaderFont reader, uint numGlyphs)
        {
            Strike value = new Strike();

            value.position         = reader.Position;
            value.numGlyphs        = numGlyphs;
            value.filePath         = reader.FilePath;
            value.ppem             = reader.ReadUInt16();
            value.ppi              = reader.ReadUInt16();
            value.glyphDataOffsets = reader.ReadUInt32Array((int)numGlyphs + 1);

            /*
             * value.glyphData = new GlyphData[numGlyphs];
             * uint[] glyphDataOffsets = value.glyphDataOffsets;
             * int length = value.glyphDataOffsets.Length - 1;
             * for (int i = 0; i < length; i++) {
             *      uint offset = glyphDataOffsets[i];
             *      uint glyphLength = glyphDataOffsets[i + 1] - offset;
             *      reader.Position = position + offset;
             *      GlyphData glyphData = GlyphData.Read(reader, glyphLength);
             *      value.glyphData[i] = glyphData;
             * }
             */
            return(value);
        }
コード例 #2
0
        public static void DrawGlyph(RendererContext context)
        {
            SbixTable sbix = context.Font.Tables.sbix;

            if (sbix == null)
            {
                //DrawGlyph(font, glyphId, g, size, 0);
                return;
            }
            Strike strike = sbix.FindStrike(context.FontSize);
            //Console.WriteLine(strike);
            GlyphData data = strike.GetGlyphData(context.GlyphId);

            if (data != null && data.data.Length > 0)
            {
                //MemoryStream stream = new MemoryStream(data2.data);
                ImageConverter converter = new ImageConverter();
                Image          image     = (Image)converter.ConvertFrom(data.data);

                float unitsPerEm = context.Font.Tables.head.unitsPerEm;
                float ascender   = context.Ascender;
                float descender  = context.Descender;
                float scale      = context.Scale;
                float baseLine   = scale * ascender;

                //Console.WriteLine("ascender " + ascender);
                //Console.WriteLine("baseLine " + baseLine);
                //Console.WriteLine("unitsPerEm * scale " + (unitsPerEm * scale));

                float width  = (context.Glyph.xMax - context.Glyph.xMin) * scale;
                float height = (context.Glyph.yMax - context.Glyph.yMin) * scale;
                // unitsPerEm * scale

                float x = context.DX + context.X * scale + data.originOffsetX;
                float y = context.DY + (context.Glyph.yMin) * scale + data.originOffsetY;

                context.Graphics.DrawImage(
                    image, x, y, width, height
                    );
                //context.Graphics.DrawLine(Pens.Black, context.X * scale, baseLine, context.X * scale + 100, baseLine);
                image.Dispose();
                //if ((font.Tables.sbix.flags & 2) > 0) {
                //	DrawGlyph(font, glyphId, g, size, 0);
                //}
            }
            else
            {
                //DrawGlyph(font, glyphId, g, size, 0);
            }
        }
コード例 #3
0
        public static SbixTable Read(BinaryReaderFont reader, MaxpTable maxp)
        {
            long      position = reader.Position;
            SbixTable value    = new SbixTable {
                version    = reader.ReadUInt16(),
                flags      = reader.ReadUInt16(),
                numStrikes = reader.ReadUInt32(),
            };
            uint numGlyphs  = maxp.numGlyphs;
            uint numStrikes = value.numStrikes;

            value.strikeOffsets = reader.ReadUInt32Array((int)numStrikes);
            value.strikes       = new Strike[numStrikes];
            for (int i = 0; i < numStrikes; i++)
            {
                uint strikeOffset = value.strikeOffsets[i];
                reader.Position  = position + strikeOffset;
                value.strikes[i] = Strike.Read(reader, numGlyphs);
            }
            return(value);
        }