Ejemplo n.º 1
0
 public void Add(FontCharCollection chars)
 {
     foreach (FontChar c in chars)
     {
         Add(c);
     }
 }
Ejemplo n.º 2
0
        public TextRecognizer(List <FontFamily> families, List <FontStyle> styles, int size_start, int size_end, int spacing)
        {
            fonts   = new List <FontCharCollection>();
            matcher = new FontCharMatcher();

            foreach (FontFamily family in families)
            {
                for (int size = size_start; size <= size_end; size += spacing)
                {
                    foreach (FontStyle style in styles)
                    {
                        if (family.IsStyleAvailable(style))
                        {
                            Font font = new Font(family, size, style, GraphicsUnit.Pixel);
                            //Console.WriteLine("Processing font: {0} [{1}, {2}]", family.GetName(0), size, style);

                            FontCharCollection fcc = new FontCharCollection(font);
                            for (int i = 33; i <= 128; i++)
                            {
                                fcc.Add(new FontChar(fcc, (char)i));
                            }
                            fcc.Add(new FontChar(fcc, '€')); // Add € symbol.

                            fcc.SortBySize();

                            fonts.Add(fcc);

                            matcher.Add(fcc);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public FontChar(FontCharCollection font_chars, char character)
        {
            this.character  = character;
            this.font_chars = font_chars;
            this.font       = font_chars.Font;
            this.color      = Color.White.ToArgb();

            string s_char = "" + character;
            Size   size   = TextRenderer.MeasureText(s_char, font, new Size(int.MaxValue, int.MaxValue));

            size.Width  *= 2;
            size.Height *= 2;
            Bitmap   char_bmp = new Bitmap(size.Width, size.Height);
            Graphics g        = Graphics.FromImage(char_bmp);

            TextRenderer.DrawText(g, s_char, font, new Point(0, 0), Color.White, TextFormatFlags.NoPrefix);

            //if ((int)character == 8364)
            //{
            //    char_bmp.Save("etmerkki.bmp");
            //    Console.ReadLine();
            //}

            //g.DrawString(s_char, font, new SolidBrush(Color.White), new Point(0, 0));
            //g.Flush();

            bitmap = new FastBitmap(BitmapAnalyzer.BoundingBitmap(char_bmp, this.color, out crop_rect));


            y_offsets   = new int[bitmap.Width];
            pixel_count = 0;

            for (int x = 0; x < bitmap.Width; x++)
            {
                y_offsets[x] = -1;

                for (int y = 0; y < bitmap.Height; y++)
                {
                    if (bitmap.GetPixel(x, y) == this.color)
                    {
                        if (y_offsets[x] < 0)
                        {
                            y_offsets[x] = y;
                        }

                        pixel_count++;
                    }
                }
            }
        }