예제 #1
0
        protected static void DrawBitmapData5(RendererContext context, BitmapSize size, GlyphBitmapData5 data)
        {
            //Console.WriteLine("data5: {0}", data5);
            BigGlyphMetrics    bigMetrics = null;
            IndexSubTableArray subTable   = size.FindSubTableArray(context.GlyphId);

            if (subTable != null)
            {
                //Console.WriteLine("Size 2: {0}", context.GlyphId);
                //Console.WriteLine("Size 3: {0}", subTable);
                bigMetrics = subTable.GetBigGlyphMetrics();
                //Console.WriteLine("Size 4: {0}", metrics);
            }
            if (bigMetrics != null)
            {
                DrawImageData(
                    context,
                    size.bitDepth,
                    bigMetrics,
                    data.imageData
                    );
            }
            else
            {
                DrawImageData(
                    context,
                    size.bitDepth,
                    size.hori.widthMax,
                    context.FontSize,
                    data.imageData
                    );
                context.X += context.FontSize;
            }
        }
예제 #2
0
 public Renderer(Font font, Interpreter interpreter)
 {
     this.font        = font;
     this.interpreter = interpreter;
     FontSize         = DefaultFontSize;
     context          = new RendererContext(font);
 }
예제 #3
0
        protected static void DrawImageData256(RendererContext context, int width, int height, byte[] data)
        {
            Bitmap bitmap = context.Bitmap;
            Color  color  = Color.Black;
            int    bx     = (int)context.DX + context.X;
            int    by     = (int)context.DY;
            int    dx     = 0;
            int    dy     = 0;
            int    length = data.Length;

            for (int i = 0; i < length; i++)
            {
                if (dx >= width)
                {
                    dx = 0;
                    dy++;
                    if (dy >= height)
                    {
                        break;
                    }
                }
                if (bx + dx > bitmap.Width)
                {
                    dx++;
                    continue;
                }
                byte alpha = data[i];
                bitmap.SetPixel(bx + dx, by + dy, Color.FromArgb(alpha, color));
                dx++;
            }
            //context.NextGlyph();
        }
예제 #4
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);
            }
        }
예제 #5
0
        public static void DrawGlyph(RendererContext context)
        {
            if (context.Glyph == null)
            {
                return;
            }
            SimpleGlyph simpleGlyph = context.Glyph.simpleGlyph;

            if (simpleGlyph == null)
            {
                return;
            }
            DrawSimpleGlyph(context, simpleGlyph);
            context.NextGlyph();
        }
예제 #6
0
        protected static void DrawImageData16(RendererContext context, BigGlyphMetrics bigMetrics, byte[] data)
        {
            Bitmap bitmap = context.Bitmap;
            Color  color  = Color.Black;
            int    width  = bigMetrics.width;
            int    height = bigMetrics.height;
            int    bx     = (int)context.DX + context.X + bigMetrics.horiBearingX;
            int    by     = (int)context.DY;
            int    dx     = 0;
            int    dy     = 0;
            int    length = data.Length;

            for (int i = 0; i < length; i++)
            {
                byte b = data[i];
                for (int n = 4; n >= 0; n -= 4)
                {
                    if (dx >= width)
                    {
                        dx = 0;
                        dy++;
                        if (dy >= height)
                        {
                            i = length;
                            break;
                        }
                    }
                    if (bx + dx > bitmap.Width)
                    {
                        dx++;
                        continue;
                    }
                    byte alpha = (byte)((b >> n) & 0x0F);
                    if (alpha == 0)
                    {
                        dx++;
                        continue;
                    }
                    alpha *= 17;
                    bitmap.SetPixel(bx + dx, by + dy, Color.FromArgb(alpha, color));
                    dx++;
                }
            }
            //context.NextGlyph();
            context.X += bigMetrics.horiAdvance;
        }
예제 #7
0
        protected static void DrawImageData2(RendererContext context, BigGlyphMetrics bigMetrics, byte[] data)
        {
            Bitmap bitmap = context.Bitmap;
            Color  color  = Color.Black;
            int    width  = bigMetrics.width;
            int    height = bigMetrics.height;
            int    bx     = (int)context.DX + context.X + bigMetrics.horiBearingX;
            int    by     = (int)context.DY;
            int    dx     = 0;
            int    dy     = 0;
            int    length = data.Length;

            for (int i = 0; i < length; i++)
            {
                byte b = data[i];
                for (int n = 0; n < 8; n++)
                {
                    if (dx >= width)
                    {
                        dx = 0;
                        dy++;
                        if (dy >= height)
                        {
                            i = length;
                            break;
                        }
                    }
                    if (bx + dx > bitmap.Width)
                    {
                        dx++;
                        continue;
                    }
                    if (((b << n) & 0x80) == 0)
                    {
                        dx++;
                        continue;
                    }
                    bitmap.SetPixel(bx + dx, by + dy, color);
                    dx++;
                }
            }
            //context.NextGlyph();
            context.X += bigMetrics.horiAdvance;
        }
예제 #8
0
        protected void DrawGlyph(RendererContext context)
        {
            if (font.Tables.CFF != null)
            {
                CFFRenderer.DrawGlyph(context);
                return;
            }
            if (UseBitmapGlyph && font.Tables.EBLC != null)
            {
                if (font.Tables.EBLC.HasSize(FontSize, FontSize))
                {
                    EBDTRenderer.DrawGlyph(context);
                    return;
                }
            }

            if (context.Glyph == null)
            {
                context.NextGlyph();
                return;
            }

            if (context.UseInterpreter)
            {
                                #if DEBUG
                if (context.Glyph.simpleGlyph != null)
                {
                    Console.WriteLine(
                        "Decode: \"{0}\"\n{1}",
                        char.ConvertFromUtf32(context.CodePoint),
                        Interpreter.Decode(context.Glyph.simpleGlyph.instructions)
                        );
                }
                                #endif
                context.Glyph = InterpretGlyph(context.Glyph);
            }

            if (font.Tables.sbix != null)
            {
                SbixRenderer.DrawGlyph(context);
            }
            TrueTypeRenderer.DrawGlyph(context);
            //Console.WriteLine("hMetric " + hMetric);
        }
예제 #9
0
        protected static void DrawImageData(RendererContext context, BitDepth bitDepth, int width, int height, byte[] data)
        {
            switch (bitDepth)
            {
            case BitDepth.BlackWhite:
                DrawImageData2(context, width, height, data);
                break;

            case BitDepth.Gray4:
                DrawImageData4(context, width, height, data);
                break;

            case BitDepth.Gray16:
                DrawImageData16(context, width, height, data);
                break;

            case BitDepth.Gray256:
                DrawImageData256(context, width, height, data);
                break;
            }
        }
예제 #10
0
        protected static void DrawImageData(RendererContext context, BitDepth bitDepth, BigGlyphMetrics bigMetrics, byte[] data)
        {
            switch (bitDepth)
            {
            case BitDepth.BlackWhite:
                DrawImageData2(context, bigMetrics, data);
                break;

            case BitDepth.Gray4:
                DrawImageData4(context, bigMetrics, data);
                break;

            case BitDepth.Gray16:
                DrawImageData16(context, bigMetrics, data);
                break;

            case BitDepth.Gray256:
                DrawImageData256(context, bigMetrics, data);
                break;
            }
        }
예제 #11
0
        public static void DrawGlyph(RendererContext context)
        {
            CFFTable      cff     = context.Font.Tables.CFF;
            HmtxTable     hmtx    = context.Font.Tables.hmtx;
            LongHorMetric hMetric = context.hMetric;

            //Console.WriteLine("glyphId: " + glyphId);

            bool hasWidth = false;

            if (hmtx != null)
            {
                hMetric = hmtx.GetMetric(context.GlyphId);
                if (cff.privateDict != null && hMetric != null)
                {
                    //Console.WriteLine("advanceWidth: {0}", hMetric.advanceWidth);
                    //Console.WriteLine("cff.privateDict.defaultWidthX: {0}", cff.privateDict.defaultWidthX);
                    hasWidth = hMetric.advanceWidth != (ushort)cff.privateDict.defaultWidthX;
                }
            }

            //Console.WriteLine();
            //Console.WriteLine("glyphId: {0}", context.GlyphId);
            //Console.WriteLine("Docode:\n{0}", CFFCharString.Decode(cff.charStrings[context.GlyphId]));
            GraphicsPath path = cff.GetGlyph(context.GlyphId, hasWidth);

            if (path == null)
            {
                if (hMetric != null)
                {
                    context.X += hMetric.advanceWidth;
                    return;
                }
                context.X += 100;
                return;
            }

            float imageSize  = context.FontSize;
            float unitsPerEm = context.Font.Tables.head.unitsPerEm;
            float ascender   = context.Font.Tables.hhea.ascender;
            float descender  = context.Font.Tables.hhea.descender;
            float scale      = imageSize / (ascender - descender);
            //float scale = imageSize / unitsPerEm;
            //scale *= 0.01f;

            float baseLine = scale * ascender;

            /*
             * GraphicsPath path = new GraphicsPath(FillMode.Alternate);
             * for (int i = 0; i < points.Count; i++) {
             *      PointF p = points[i];
             *      Console.WriteLine("Point: {0}", points[i]);
             *      p.X /= 10;
             *      p.Y /= 10;
             *      //p.X = -p.X;
             *      //p.Y = -p.Y;
             *      //p.X += 100;
             *      //p.Y += 100;
             *      points[i] = p;
             * }
             * Console.WriteLine();
             */

            //path.AddLines(points.ToArray());
            //path.Transform(new Matrix(scale, 0, 0, -scale, (float)Math.Round(x * scale), baseLine));

            float x = context.DX + context.X * scale;
            float y = context.DY + baseLine;

            path.Transform(new Matrix(
                               scale, 0,
                               0, -scale,
                               x, y)
                           );
            path.CloseFigure();
            context.Graphics.FillPath(Brushes.Black, path);

            //Console.WriteLine("hMetric.advanceWidth: {0}", hMetric.advanceWidth);
            if (hMetric != null)
            {
                context.X += hMetric.advanceWidth;
                return;
            }
            context.X += 100;
        }
예제 #12
0
        public static void DrawGlyph(RendererContext context)
        {
            EBLCTable EBLC = context.Font.Tables.EBLC;
            EBDTTable EBDT = context.Font.Tables.EBDT;

            //Bitmap bitmap = context.Bitmap;

            BitmapSize size = EBLC.GetBitmapSize(context.FontSize, context.FontSize);
            //Console.WriteLine("bitDepth: {0}", size.bitDepth);
            //Console.WriteLine("subTables.Length: {0}", size.subTables.Length);

            //for (int i = 0; i < size.subTables.Length; i++) {
            //	Console.WriteLine("subTables {0}: {1}", i, size.subTables[i]);
            //}
            //Console.WriteLine("flags: {0}", size.flags);

            //GlyphBitmapData data = EBDT.bitmapData[0x53F8];
            GlyphBitmapData data = EBDT.GetGlyphBitmapData(size.index, context.GlyphId);

            if (data == null)
            {
                data = EBDT.GetGlyphBitmapData(size.index, 0);
            }
            if (data == null)
            {
                context.X += context.FontSize;
                return;
            }
            //GlyphBitmapData data = EBDT.bitmapData[0x835];
            switch (data.format)
            {
            case 1:
                GlyphBitmapData1 data1 = data as GlyphBitmapData1;
                //Console.WriteLine("data7: {0}", data7);
                DrawImageData(
                    context,
                    size.bitDepth,
                    data1.smallMetrics,
                    data1.imageData
                    );
                break;

            case 2:
                GlyphBitmapData2 data2 = data as GlyphBitmapData2;
                //Console.WriteLine("data7: {0}", data7);
                DrawImageData(
                    context,
                    size.bitDepth,
                    data2.smallMetrics,
                    data2.imageData
                    );
                break;

            case 5:
                DrawBitmapData5(context, size, data as GlyphBitmapData5);
                break;

            case 6:
                GlyphBitmapData6 data6 = data as GlyphBitmapData6;
                //Console.WriteLine("data7: {0}", data);
                DrawImageData(
                    context,
                    size.bitDepth,
                    data6.bigMetrics,
                    data6.imageData
                    );
                break;

            case 7:
                GlyphBitmapData7 data7 = data as GlyphBitmapData7;
                //Console.WriteLine("data7: {0}", data7);
                DrawImageData(
                    context,
                    size.bitDepth,
                    data7.bigMetrics,
                    data7.imageData
                    );
                break;

            case 8:
                break;

            case 9:
                break;
            }
            //context.X += context.FontSize;
        }
예제 #13
0
        protected static void DrawSimpleGlyph(RendererContext context, SimpleGlyph simpleGlyph)
        {
            LongHorMetric hMetric = context.hMetric;
            //float unitsPerEm = font.Tables.head.unitsPerEm;
            float scale = context.Scale;
            //float scale = imageSize / unitsPerEm;
            //scale *= 0.01f;

            //float xMin = scale * (glyph.xMin + font.Tables.head.xMin);
            //float yMin = scale * (glyph.yMin + font.Tables.head.yMin);
            float xMin = context.X;            // + glyph.xMin;
            float yMin = 0;

            if (hMetric != null)
            {
                //Console.WriteLine("hMetric.lsb: {0}", hMetric.lsb);
                //Console.WriteLine("hMetric.advanceWidth " + hMetric.advanceWidth);
                xMin += context.Glyph.xMin - hMetric.lsb;
                xMin  = Math.Max(xMin, 0);
            }
            else
            {
                xMin += context.Glyph.xMin;
            }

            xMin *= scale;
            yMin  = context.Ascender * scale;
            xMin += context.DX;
            yMin += context.DY;

            //xMin = (float)Math.Round(xMin);

            /*
             * //Console.WriteLine("unitsPerEm " + unitsPerEm);
             * Console.WriteLine("ascender " + ascender);
             * Console.WriteLine("descender " + descender);
             * Console.WriteLine("scale " + scale);
             * Console.WriteLine("baseLine " + baseLine);
             * Console.WriteLine("glyph.xMin " + glyph.xMin);
             * Console.WriteLine("glyph.xMax " + glyph.xMax);
             * Console.WriteLine("glyph.yMin " + glyph.yMin);
             * Console.WriteLine("glyph.yMax " + glyph.yMax);
             * Console.WriteLine("head.xMin " + font.Tables.head.xMin);
             * Console.WriteLine("xMin " + xMin);
             * Console.WriteLine("yMin " + yMin);
             * Console.WriteLine();
             * //*/


            ushort[]           endPtsOfContours = simpleGlyph.endPtsOfContours;
            SimpleGlyphFlags[] flags            = simpleGlyph.flags;
            short[]            xCoordinates     = simpleGlyph.xCoordinates;
            short[]            yCoordinates     = simpleGlyph.yCoordinates;

            GraphicsPath path   = new GraphicsPath(FillMode.Alternate);
            int          length = endPtsOfContours.Length;
            int          start  = 0;

            PointF[] on  = new PointF[2];
            PointF[] off = new PointF[8];
            for (int n = 0; n < length; n++)
            {
                float fx = 0, fy = 0;
                int   onCount  = 0;
                int   offCount = 0;
                int   end      = endPtsOfContours[n];

                // first point is not on-curve
                if ((flags[start] & SimpleGlyphFlags.ON_CURVE_POINT) == 0)
                {
                    float x0 = xMin + xCoordinates[end] * scale;
                    float y0 = yMin - (yCoordinates[end] * scale);
                    on[0].X = x0;
                    on[0].Y = y0;
                    onCount++;
                    fx = x0;
                    fy = y0;
                }

                for (int i = start; i <= end; i++)
                {
                    float x0 = xMin + xCoordinates[i] * scale;
                    float y0 = yMin - (yCoordinates[i] * scale);
                    if ((flags[i] & SimpleGlyphFlags.ON_CURVE_POINT) > 0)
                    {
                        //if (onCount == 0) {
                        //	fx = x0;
                        //	fy = y0;
                        //}
                        on[onCount].X = x0;
                        on[onCount].Y = y0;
                        onCount++;
                        if (onCount == 2)
                        {
                            CreateCurvePoints(path, on, off, offCount);
                            onCount  = 1;
                            offCount = 0;
                            on[0].X  = on[1].X;
                            on[0].Y  = on[1].Y;
                        }
                        else
                        {
                            fx = x0;
                            fy = y0;
                        }
                    }
                    else
                    {
                        off[offCount].X = x0;
                        off[offCount].Y = y0;
                        offCount++;
                    }
                }
                if (onCount == 1)
                {
                    on[1].X = fx;
                    on[1].Y = fy;
                    CreateCurvePoints(path, on, off, offCount);
                }
                path.CloseFigure();
                start = end + 1;
            }
            context.Graphics.FillPath(Brushes.Black, path);
            path.Dispose();
        }