Ejemplo n.º 1
0
 public bool Equals(BitFont font)
 {
     if (IsSystemFont && font.IsSystemFont)
     {
         return(ID == font.ID);
     }
     if (chars == null)
     {
         EnsureLoaded();
     }
     if (font.chars == null)
     {
         font.EnsureLoaded();
     }
     if (font.chars.Length != chars.Length || font.Width != Width || font.Height != Height)
     {
         return(false);
     }
     for (int i = 0; i < chars.Length; i++)
     {
         if (!chars[i].Equals(font.chars[i]))
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 2
0
        public static BitFont FromResource(string resourceName, int numChars, int codePage, int width, int height)
        {
            var font = new BitFont(numChars, width, height, codePage);

            font.Load(new BinaryReader(Assembly.GetCallingAssembly().GetManifestResourceStream(resourceName)));
            return(font);
        }
Ejemplo n.º 3
0
 public Page(CharacterDocument document, Size canvasSize, BitFont font, Palette palette)
 {
     this.document          = document;
     canvas                 = new MemoryCanvas(canvasSize);
     pal                    = palette;
     pal.CollectionChanged += InternalPaletteChanged;
     this.Font              = font;
 }
Ejemplo n.º 4
0
        public Point ScreenToCharacter(Point point)
        {
            BitFont font = CurrentPage.Font;
            PointF  ptf  = point;

            ptf /= font.Size;
            ptf /= ZoomRatio;

            return(new Point(ptf));
        }
Ejemplo n.º 5
0
        public CharacterDocument(DocumentInfo info) : base(info)
        {
            defaultFont    = BitFont.GetStandard8x16();
            defaultSize    = new Size(80, EditSize);
            defaultPalette = Palette.GetDosPalette();
            Initialize(1, defaultSize);

            Info.Use9xChanged        += Info_Use9xChanged;
            Info.SelectedFontChanged += Info_SelectedFontChanged;
            SetFont(true);
        }
Ejemplo n.º 6
0
 public static BitFont GetStandard8x8()
 {
     if (standard8x8 == null)
     {
         standard8x8                = BitFont.FromResource("Pablo.Formats.Character.Fonts.DOS.CP437.F08", 256, 437, 8, 8);
         standard8x8.ID             = "CP 437 8x8";
         standard8x8.LegacyRatio    = 1.2f;
         standard8x8.SauceID        = "IBM VGA50";
         standard8x8.Name           = "IBM PC - " + standard8x8.ID;
         standard8x8.IsSystemFont   = true;
         standard8x8.IsStandardFont = true;
     }
     return(standard8x8);
 }
Ejemplo n.º 7
0
 public static BitFont GetStandard8x16()
 {
     if (standard8x16 == null)
     {
         standard8x16                = BitFont.FromResource("Pablo.Formats.Character.Fonts.DOS.CP437.F16", 256, 437, 8, 16);
         standard8x16.ID             = "CP 437 8x16";
         standard8x16.SauceID        = "IBM VGA";
         standard8x16.LegacyRatio    = 1.2f;
         standard8x16.Name           = "IBM PC - " + standard8x16.ID;
         standard8x16.IsSystemFont   = true;
         standard8x16.IsStandardFont = true;
     }
     return(standard8x16);
 }
Ejemplo n.º 8
0
        public static BitFont FromResource(string resourceName, int numChars, int codePage, int width, int height, string id, string name, BitFontSet set, bool isSystemFont, string sauceID = null, float?ratio = null, Assembly assembly = null)
        {
            var font = new BitFont(resourceName, numChars, width, height, codePage, assembly ?? Assembly.GetCallingAssembly());

            font.ID           = id;
            font.Name         = name;
            font.FontSet      = set;
            font.IsSystemFont = isSystemFont;
            font.SauceID      = sauceID;
            if (ratio != null)
            {
                font.LegacyRatio = ratio.Value;
            }
            return(font);
        }
Ejemplo n.º 9
0
        public void UpdateRegion(Rectangle rect)
        {
            BitFont font     = CurrentPage.Font;
            var     destrect = (RectangleF)rect;

            destrect *= font.Size;
            var w = (ZoomRatio.Width != 1) ? 1 / ZoomRatio.Width : 0;
            var h = (ZoomRatio.Height != 1) ? 1 / ZoomRatio.Height : 0;

            destrect.Inflate(w, h);
            OnUpdateRegion(Rectangle.Ceiling(destrect));
            if (preview != null)
            {
                preview.UpdateRegion(rect);
            }
        }
Ejemplo n.º 10
0
        public static BitFontSet AmigaFont()
        {
            var fontSet = new BitFontSet {
                Name = "Amiga"
            };
            const int codePage = 1252;
            const int numChars = 256;

            fontSet.Fonts.Add(BitFont.FromResource("Pablo.Formats.Character.Fonts.Amiga.MicroKnight.F16", numChars, codePage, 8, 16, "amiga-microknight", "MicroKnight", fontSet, true, "Amiga MicroKnight", 1.2f));
            fontSet.Fonts.Add(BitFont.FromResource("Pablo.Formats.Character.Fonts.Amiga.MicroKnightPlus.F16", numChars, codePage, 8, 16, "amiga-microknight+", "MicroKnight+", fontSet, true, "Amiga MicroKnight+", 1.2f));
            fontSet.Fonts.Add(BitFont.FromResource("Pablo.Formats.Character.Fonts.Amiga.mO'sOul.F16", numChars, codePage, 8, 16, "amiga-mOsOul", "mO'sOul", fontSet, true, "Amiga mOsOul", 1.2f));
            fontSet.Fonts.Add(BitFont.FromResource("Pablo.Formats.Character.Fonts.Amiga.P0T-NOoDLE.F16", numChars, codePage, 8, 16, "amiga-pot-noodle", "P0T-NOoDLE", fontSet, true, "Amiga P0T-NOoDLE", 1.2f));
            fontSet.Fonts.Add(BitFont.FromResource("Pablo.Formats.Character.Fonts.Amiga.Topaz_a1200.F16", numChars, codePage, 8, 16, "amiga-topaz-1200", "Topaz 1200", fontSet, true, "Amiga Topaz 2", 1.2f));
            fontSet.Fonts.Add(BitFont.FromResource("Pablo.Formats.Character.Fonts.Amiga.Topaz_a500.F16", numChars, codePage, 8, 16, BitFont.StandardAmigaFontID, "Topaz 500", fontSet, true, "Amiga Topaz 1", 1.2f));
            fontSet.Fonts.Add(BitFont.FromResource("Pablo.Formats.Character.Fonts.Amiga.TopazPlus_a1200.F16", numChars, codePage, 8, 16, "amiga-topaz-plus-1200", "Topaz+ 1200", fontSet, true, "Amiga Topaz 2+", 1.2f));
            fontSet.Fonts.Add(BitFont.FromResource("Pablo.Formats.Character.Fonts.Amiga.TopazPlus_a500.F16", numChars, codePage, 8, 16, "amiga-topaz-plus-500", "Topaz+ 500", fontSet, true, "Amiga Topaz 1+", 1.2f));
            return(fontSet);
        }
Ejemplo n.º 11
0
 public void InvalidateCharacterRegion(Rectangle rect, bool includePreview, bool previewOnly = false)
 {
     rect.Normalize();
     if (!previewOnly)
     {
         BitFont    font  = CurrentPage.Font;
         RectangleF rectf = rect;
         rectf *= font.Size;
         rectf *= ZoomRatio;
         int w = (ZoomRatio.Width != 1) ? 1 : 0;
         int h = (ZoomRatio.Height != 1) ? 1 : 0;
         rectf.Inflate(w, h);
         OnInvalidateRegion(Rectangle.Ceiling(rectf));
     }
     if (includePreview && preview != null)
     {
         preview.InvalidateCharacterRegion(rect, false);
     }
 }
Ejemplo n.º 12
0
        public void EnsureVisible(Point point)
        {
            BitFont font = CurrentPage.Font;
            var     rect = new RectangleF(point * font.Size, font.Size);

            rect *= ZoomRatio;

            Point scrollPos = Viewer.ScrollPosition;
            Point oldPos    = scrollPos;

            Size viewSize = Viewer.ViewSize;

            if (rect.InnerBottom > scrollPos.Y + viewSize.Height)
            {
                scrollPos.Y = (int)rect.InnerBottom - viewSize.Height;
            }
            if (rect.InnerRight > scrollPos.X + viewSize.Width)
            {
                scrollPos.X = (int)rect.InnerRight - viewSize.Width;
            }
            if (rect.Top < scrollPos.Y)
            {
                scrollPos.Y = (int)rect.Top;
            }
            if (rect.Left < scrollPos.X)
            {
                scrollPos.X = (int)rect.Left;
            }
            if (scrollPos.Y < 0)
            {
                scrollPos.Y = 0;
            }
            if (scrollPos.X < 0)
            {
                scrollPos.X = 0;
            }

            if (scrollPos != oldPos)
            {
                Viewer.ScrollPosition = scrollPos;
            }
        }
Ejemplo n.º 13
0
        public static BitFontSet FromFontResources(string resource, string name, int codePage, int[] heights, bool isSystemFont = true, int[] fallbackCodePages = null, int numChars = 256, Assembly asm = null)
        {
            asm = asm ?? Assembly.GetExecutingAssembly();
            var fontSet = new BitFontSet {
                Name = name
            };

            foreach (var height in heights)
            {
                const int width        = 8;
                var       resourceName = string.Format("{0}.F{1:00}", resource, height);
                var       id           = string.Format("CP {0} {1}x{2}", codePage, width, height);
                var       bitFont      = BitFont.FromResource(resourceName, numChars, codePage, width, height, id, id, fontSet, isSystemFont);
                bitFont.FallbackCodePages = fallbackCodePages;
                bitFont.SauceID           = GetSauceID(height, codePage);
                fontSet.Fonts.Add(bitFont);
            }

            return(fontSet);
        }
Ejemplo n.º 14
0
 internal void SetFont(bool reload, bool sendEvent = true)
 {
     if (Pages[0] == null)
     {
         return;
     }
     if (reload)
     {
         defaultFont = Info.SelectedFont;
         if (!EditMode && Sauce != null)
         {
             var info = Sauce.TypeInfo as Sauce.Types.BaseText.DataTypeInfo;
             if (info != null)
             {
                 defaultFont = info.GetFont(Info.GetFonts()) ?? defaultFont;
             }
         }
     }
     else
     {
         defaultFont = Pages[0].Font;
     }
     if (defaultFont.Width >= 8 && defaultFont.Width <= 9)
     {
         int newWidth = Use9x ? 9 : 8;
         if (newWidth != defaultFont.Width)
         {
             defaultFont = new BitFont(defaultFont);
             defaultFont.Resize(newWidth, defaultFont.Height, false, Use9x);
         }
         Pages[0].Font = defaultFont;
     }
     if (sendEvent)
     {
         OnSizeChanged(EventArgs.Empty);
     }
 }
Ejemplo n.º 15
0
        public BitFont(BitFont source)
        {
            if (source.chars == null)
            {
                source.EnsureLoaded();
            }
            ID             = source.ID;
            Name           = source.Name;
            FontSet        = source.FontSet;
            CodePage       = source.CodePage;
            chars          = new FontCharacter[source.chars.Length];
            Width          = source.Width;
            Height         = source.Height;
            LegacyRatio    = source.LegacyRatio;
            Is9xFont       = source.Is9xFont;
            SauceID        = source.SauceID;
            IsStandardFont = source.IsStandardFont;
            IsSystemFont   = source.IsSystemFont;

            for (int i = 0; i < chars.Length; i++)
            {
                chars[i] = new FontCharacter(source.chars[i], this);
            }
        }
Ejemplo n.º 16
0
 public BitFontSet(BitFont font)
 {
     this.CodePage = font.CodePage;
     this.fonts.Add(font);
 }
Ejemplo n.º 17
0
 public FontCharacter(BitFont font)
 {
     this.font = font;
     data      = new int[(font.Width * font.Height + 31) / 32];
 }
Ejemplo n.º 18
0
 internal FontCharacter(FontCharacter fc, BitFont font)
 {
     data      = (int[])fc.data.Clone();
     this.font = font;
 }
Ejemplo n.º 19
0
 public void GenerateRegion(Bitmap bitmap, Rectangle rect, Size fontSize, BitFont customFont, Palette customPalette, bool iceColor, bool blinkOn, Point?cursorPosition, IGenerateRegion generator)
 {
     GenerateRegion(canvas, bitmap, rect, fontSize, customFont ?? font, customPalette ?? pal, iceColor, blinkOn, cursorPosition, generator);
 }
Ejemplo n.º 20
0
        public unsafe static void GenerateRegion(Canvas canvas, Bitmap bitmap, Rectangle rect, Size fontSize, BitFont font, Palette pal, bool iceColor, bool blinkOn, Point?cursorPosition, IGenerateRegion generator)
        {
            unchecked
            {
                //Console.WriteLine ("Generating region: {0}, bitmap size: {1}", rect, bitmap.Size);

                /*
                 * hmm.. quite a bit faster drawing character by character (less array lookups)
                 */
                var startCanvas = new Point(rect.Left / fontSize.Width, rect.Top / fontSize.Height);
                var startFont   = new Point(((rect.Left % fontSize.Width) * font.Width) / fontSize.Width, ((rect.Top % fontSize.Height) * font.Height) / fontSize.Height);

                rect.Width  = (rect.Width + fontSize.Width);
                rect.Height = rect.Height + fontSize.Height;
                var endCanvas = new Point((rect.InnerRight + 1) / fontSize.Width, (rect.InnerBottom + 1) / fontSize.Height);
                var endFont   = new Point((((rect.InnerRight + 1) % fontSize.Width) * font.Width) / fontSize.Width, (((rect.InnerBottom + 1) % fontSize.Height) * font.Height) / fontSize.Height);

                var rDraw = new Rectangle(startCanvas.X, startCanvas.Y, endCanvas.X - startCanvas.X, endCanvas.Y - startCanvas.Y);
                if (endFont.X == 0 && rDraw.Width > 1)
                {
                    rDraw.Width--;
                    endFont.X = font.Width;
                }
                if (endFont.Y == 0 && rDraw.Height > 1)
                {
                    rDraw.Height--;
                    endFont.Y = font.Height;
                }
                rDraw.Restrict(canvas.Size);
                //if (rDraw.InnerRight > canvas.Width) { rDraw.Width = rDraw.X

                var rectScn = new Rectangle(0, 0, rDraw.Width * font.Width - startFont.X - (font.Width - endFont.X), rDraw.Height * font.Height - startFont.Y - (font.Height - endFont.Y));
                if (rectScn.Width == 0 || rectScn.Height == 0)
                {
                    return;
                }

                CanvasElement ce;

                BitmapData bd   = bitmap.Lock();
                var        pRow = (byte *)bd.Data;

                uint *pCharStart;
                int   foreColor, backColor;
                int   cursorForeColor = 0, cursorBackColor = 0;

                int charStartY = startFont.Y;
                if (startFont.Y < 0)
                {
                    pRow      += (bd.ScanWidth * (-startFont.Y));
                    charStartY = 0;
                }
                int fontHeight = font.Height;

                generator = generator ?? new EmptyGenerator();

                int scanWidth = bd.ScanWidth;
                if (bd.Flipped)
                {
                    pRow     += bd.ScanWidth * (rDraw.Height - 1);
                    scanWidth = -scanWidth;
                }
                var pt = new Point();
                for (pt.Y = rDraw.Top; pt.Y <= rDraw.InnerBottom; pt.Y++)
                {
                    pCharStart = (uint *)pRow;
                    int charStartX;
                    if (startFont.X < 0)
                    {
                        pCharStart -= startFont.X;
                        charStartX  = 0;
                    }
                    else
                    {
                        charStartX = startFont.X;
                    }
                    if (pt.Y == rDraw.InnerBottom)
                    {
                        fontHeight = endFont.Y;
                    }
                    if (pt.Y >= 0 && pt.Y < canvas.Height)
                    {
                        for (pt.X = rDraw.Left; pt.X <= rDraw.InnerRight; pt.X++)
                        {
                            var charEndX = pt.X == rDraw.InnerRight ? endFont.X : font.Width;
                            if (pt.X >= 0 && pt.X < canvas.Width)
                            {
                                ce = generator.GetElement(pt, canvas) ?? canvas[pt];

                                /*
                                 */
                                foreColor = pal.GetRGBColor(ce.Foreground);
                                backColor = pal.GetRGBColor(iceColor ? ce.Background : ce.Attribute.BackgroundOnly);
                                generator.TranslateColour(pt, ref foreColor, ref backColor);
                                bool cursor = false;
                                if (cursorPosition != null && cursorPosition.Value == pt)
                                {
                                    cursorForeColor = bd.TranslateArgbToData(~foreColor | (int)0xff000000);
                                    cursorBackColor = bd.TranslateArgbToData(~backColor | (int)0xff000000);
                                    cursor          = true;
                                }

                                /*
                                 *
                                 * foreColor = pal[ce.Foreground]; //foreu = pal.GetRGBColor(ce.Foreground);
                                 * if (iceColor) backColor = pal[ce.Background]; //backu = pal.GetRGBColor(ce.Background);
                                 * else backColor = pal[ce.Attribute.BackgroundOnly]; //backu = pal.GetRGBColor(ce.Background & 0x7);
                                 * /*
                                 */
                                bool shouldBeOn = iceColor | blinkOn | !ce.Attribute.Blink;
                                var  fc         = font[ce.Character];
                                foreColor = bd.TranslateArgbToData(foreColor);
                                backColor = bd.TranslateArgbToData(backColor);
                                // got our char & attrib info, now draw the character PIXEL BY PIXEL!
                                var pCharY = (byte *)pCharStart;
                                var chpos  = charStartY * font.Width;
                                for (int chary = charStartY; chary < fontHeight; chary++)
                                {
                                    if (cursor && chary > fontHeight - 3)
                                    {
                                        foreColor = cursorForeColor;
                                        backColor = cursorBackColor;
                                        cursor    = false;
                                    }
                                    var pCharX = (int *)pCharY;
                                    var endpos = chpos + charEndX;
                                    var charx  = chpos + charStartX;
                                    var data   = fc.GetData(charx / 32);
                                    var idx    = 1 << charx;
                                    for (; charx < endpos; charx++)
                                    {
                                        if (idx == 0)
                                        {
                                            idx  = 1 << charx;
                                            data = fc.GetData(charx / 32);
                                        }

                                        var on = shouldBeOn && (data & idx) != 0;
                                        idx       <<= 1;
                                        *(pCharX++) = on ? foreColor : backColor;
                                    }
                                    pCharY += scanWidth;
                                    chpos  += font.Width;
                                }
                            }
                            pCharStart += (font.Width - charStartX);
                            if (pt.X == rDraw.Left)
                            {
                                charStartX = 0;
                            }
                        }
                    }
                    pRow += (fontHeight - charStartY) * scanWidth;
                    if (pt.Y == rDraw.Top)
                    {
                        charStartY = 0;
                    }
                }

                bd.Dispose();
            }
        }
Ejemplo n.º 21
0
 public void SetFont(BitFont font)
 {
     Pages[0].Font = font;
     SetFont(false);
 }
Ejemplo n.º 22
0
        public void Load(Stream stream, int[] forceCodePage = null, bool isSystemFont = true)
        {
            FallbackCodePages = forceCodePage;
            var br         = new BinaryReader(stream);
            var headerSize = br.ReadInt16();

            /*var nextOffset =*/
            br.ReadInt32();
            var deviceType = br.ReadInt16();

            // must be 1
            FallbackCodePages = forceCodePage;

            /*var deviceName =*/
            br.ReadBytes(8);
            var codePage = br.ReadInt16();

            CodePage = codePage;
            /*var reserved =*/
            br.ReadBytes(6);
            /*var offset =*/
            br.ReadInt32();

            if (headerSize > 0x1C)
            {
                br.ReadBytes(0x1C - headerSize);
            }

            // CodePageInfoHeader
            //stream.Position = offset;
            /*var version =*/
            br.ReadInt16();
            var numFonts = br.ReadInt16();

            /*var size =*/
            br.ReadInt16();
            for (int i = 0; i < numFonts; i++)
            {
                if (deviceType == 1)
                {
                    // screen
                    var height = br.ReadByte();
                    var width  = br.ReadByte();
                    // should be 8
                    /*var yaspect =*/
                    br.ReadByte();
                    /*var xaspect =*/
                    br.ReadByte();
                    var numChars = br.ReadInt16();
                    var font     = new BitFont(numChars, width, height, CodePage);
                    font.ID                = string.Format("{0} {1}x{2}", codePage, width, height);
                    font.Name              = string.Format("CP {0} {1}x{2}", codePage, width, height);
                    font.IsSystemFont      = isSystemFont;
                    font.FallbackCodePages = forceCodePage;
                    font.FontSet           = this;
                    font.Load(br);
                    fonts.Add(font);
                }
                else if (deviceType == 2)
                {
                    // printer
                    throw new NotImplementedException();
                }
            }
            fonts.Sort((x, y) => x.Height.CompareTo(y.Height));
        }