Exemplo n.º 1
0
        public bool FromFixedHeightStaggered(string sFile, int iCharHeight)          //this is named FromFixedHeightStaggered while the function it called anim.SplitFromFixedHeightStaggered
        {
            RReporting.sLastFile = sFile + "...";
            bool  bGood      = false;
            RAnim animNormal = null;

            bGood = Init();
            try {
                if (!sFile.EndsWith(".png"))
                {
                    animNormal = new RAnim();
                    RImage riNormal = new RImage();
                    RReporting.sLastFile = sFile + ".png";
                    if (!riNormal.Load(sFile + ".png", 4))                    //assumes 32-bit is needed
                    {
                        RReporting.ShowErr("Cannot load font file", "", "RAnim FromFixedHeightStaggered(\"" + RString.SafeString(sFile) + ".png\")");
                    }
                    RReporting.sParticiple = "splitting normal font image";
                    bGood = animNormal.SplitFromFixedHeightStaggered(riNormal, iCharHeight);
                    if (bGood)
                    {
                        Normal = animNormal;
                        bGood  = Normal != null;
                        if (Normal == null)
                        {
                            RReporting.ShowErr("failed to load normal font though split image returned true", "checking loaded normal font", "rfont_bgra32 FromFixedHeightStaggered");
                        }
                        if (File.Exists(sFile + "-bold.png"))
                        {
                            RReporting.sLastFile = sFile + "-bold.png";
                            if (animarrGlyphType[RFont.GlyphTypeBold] == null)
                            {
                                Bold = new RAnim();
                            }
                            RImage riBold = new RImage();
                            RReporting.sParticiple = "loading bold font image";
                            riBold.Load(sFile + "-bold.png", 4);                         //assumes 32-bit is needed
                            if (!Bold.SplitFromFixedHeightStaggered(riBold, iCharHeight))
                            {
                                RReporting.sParticiple = "falling back to generated bold font";
                                bGood = false;
                                RReporting.ShowErr("Could not split image to bold font frames", "separating bold font frames", "rfont_bgra32 FromFixedHeightStaggered");
                                Bold = animNormal.Copy();
                                //TODO: embolden font manually
                            }
                        }
                        else
                        {
                            RReporting.sParticiple = "getting bold font image from normal";
                            Bold = animNormal.Copy();
                            if (Bold != null)
                            {
                                //TODO: embolden font manually
                            }
                            else
                            {
                                bGood = false;
                                RReporting.ShowErr("Could not copy font frames", "copying font frames to bold font frames", "rfont_bgra32 FromFixedHeightStaggered");
                            }
                        }
                        RReporting.sParticiple = "getting italic font image from normal";
                        Italic = Normal.Copy();
                        if (Italic != null)
                        {
                            //TODO: italicize font manually
                        }
                        else
                        {
                            bGood = false;
                            RReporting.ShowErr("Could not copy font frames", "copying font frames to italic font frames", "rfont_bgra32 FromFixedHeightStaggered");
                        }
                        RReporting.sParticiple = "getting bold italic font image from bold";
                        BoldItalic             = Bold.Copy();
                        if (BoldItalic != null)
                        {
                            //TODO: italicize bold font manually
                        }
                        else
                        {
                            bGood = false;
                            RReporting.ShowErr("Could not copy font frames", "copying font frames to bold italic font frames", "rfont_bgra32 FromFixedHeightStaggered");
                        }
                        CalculateSpacing(GlyphTypeNormal);
                    }
                    else
                    {
                        RReporting.ShowErr("Could not split image to font frames", "separating font frames", "rfont_bgra32 FromFixedHeightStaggered");
                    }
                }
                else
                {
                    bGood = false;
                    RReporting.ShowErr("Font file base name must not end with extension--must have assumed png extension.", "checking raster font file", "rfont_bgra32 FromFixedHeightStaggered");
                }
            }
            catch (Exception exn) {
                bGood = false;
                RReporting.ShowExn(exn, "Splitting Proportional Font Glyphs", "FromFixedHeightStaggered(" + sFile + "," + iCharHeight.ToString() + ")");
            }
            if (this.animarrGlyphType != null)
            {
                for (int i = 0; i < RFont.iGlyphTypes; i++)
                {
                    if (animarrGlyphType[i] == null)
                    {
                        RReporting.ShowErr("Null glyph type " + RFont.GlyphTypeToString(i), "getting glyphs from images", "FromFixedHeightStaggered(sFile=" + RReporting.StringMessage(sFile, true) + ",iCharHeight=" + iCharHeight + ")");
                    }
                    else if (!animarrGlyphType[i].FrameIsCached(0))
                    {
                        RReporting.ShowErr("First glyph is null in glyph type " + RFont.GlyphTypeToString(i), "getting glyphs from images", "FromFixedHeightStaggered(sFile=" + RReporting.StringMessage(sFile, true) + ",iCharHeight=" + iCharHeight + ")");
                    }
                }
            }
            else
            {
                RReporting.ShowErr("Null glyph type array", "getting glyphs from images", "FromFixedHeightStaggered(sFile=" + RReporting.StringMessage(sFile, true) + ",iCharHeight=" + iCharHeight + ")");
            }
            return(bGood);
        }        //end FromFixedHeightStaggered