Ejemplo n.º 1
0
        static void ExtractFontPack(string pakPath, string txmPath, string basePath)
        {
            if (basePath == null)
            {
                basePath = pakPath + "_extracted";
            }
            using (Stream fs = Utils.CheckDecompress(File.OpenRead(txmPath)))
                using (Stream datFs = Utils.CheckDecompress(File.OpenRead(pakPath)))
                {
                    var          fontTxmHeader = new TxmHeader();
                    BinaryReader br            = new BinaryReader(fs);
                    fontTxmHeader.Read(br);
                    var palette = TxmConversion.ReadRgba32Palette(br, fontTxmHeader.ClutWidth, fontTxmHeader.ClutHeight);

                    var fontPak = new FontPack();
                    fontPak.Read(datFs);
                    Directory.CreateDirectory(basePath);

                    foreach (var ch in fontPak.Characters)
                    {
                        using MemoryStream ms = new MemoryStream(fontPak[ch]);
                        BinaryReader charBr = new BinaryReader(ms);
                        using (var img = TxmConversion.ConvertTxmIndexed4bpp(charBr, 24, 22, palette))
                        {
                            img.SaveAsPng(Path.Combine(basePath, $"{ch}.png"));
                        }
                    }
                }
        }
Ejemplo n.º 2
0
            public string direction = "horizontal";//horizontal|vertical
            public FontPack FromJson(string json)
            {
                FontPack model = new FontPack();

                if (string.IsNullOrEmpty(json))
                {
                    return(model);
                }
                json  = HttpUtility.UrlDecode(json);
                model = JsonConvert.DeserializeObject <FontPack>(json);
                //------------------
                if (string.IsNullOrEmpty(model.bkcolor))
                {
                    model.bkcolor = "";
                }
                if (string.IsNullOrEmpty(model.color))
                {
                    model.color = "#fff";
                }
                if (model.size < 1)
                {
                    model.size = 12;
                }
                return(model);
            }
Ejemplo n.º 3
0
            public string direction = "";//horizontal|vertical
            public FontPack FromJson(string json)
            {
                FontPack model = new FontPack();

                if (string.IsNullOrEmpty(json))
                {
                    return(model);
                }
                //json = HttpUtility.UrlDecode(json);
                //json = HttpUtility.HtmlDecode(json);
                model = JsonConvert.DeserializeObject <FontPack>(json);
                //ZoomLa.BLL.ZLLog.L(model.text);
                //------------------
                //去除首尾空格,便于计算,只允许大写字母,避免竖排靠边
                model.text = model.text.Trim();
                if (string.IsNullOrEmpty(model.bkcolor))
                {
                    model.bkcolor = "";
                }
                if (string.IsNullOrEmpty(model.color))
                {
                    model.color = "#fff";
                }
                if (string.IsNullOrEmpty(model.direction))
                {
                    model.direction = "horizontal";
                }
                if (model.size < 1)
                {
                    model.size = 12;
                }
                model.family = model.family.Replace("_", " ");
                return(model);
            }
Ejemplo n.º 4
0
        private static FontPack LoadFromResource(string id)
        {
            FontPack pack;

            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("RomanPort.SpectrumVideoRenderer.Core.Framework.FontPacks." + id + ".sdrf"))
                pack = FontPack.FromStream(stream);
            return(pack);
        }
Ejemplo n.º 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            switch (Action)
            {
            case "text":
            {
                FontPack model = new FontPack().FromJson(Request["model"]);
                if (string.IsNullOrEmpty(model.text))
                {
                    throw new Exception("文字内容不能为空");
                }
                int bmpLen = 0;
                int size   = GetFontSize(model.text, ref bmpLen);       //自动计算出文字大小
                //------------------------------------
                Bitmap   empty = new Bitmap(bmpLen, (int)(size * 1.5)); //创建图片背景
                Graphics g     = Graphics.FromImage(empty);
                //g.Clear(model.ColorHx16toRGB(model.bkcolor));//清除画面,填充背景
                g.Clear(Color.FromArgb(0));
                Font mFont = new Font(model.family, size, FontStyle.Regular);
                g.DrawString(model.text, mFont,
                             new SolidBrush(model.ColorHx16toRGB(model.color)),//Color.FromArgb(100,255,255,255)
                             new Point(0, 0));
                empty.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            }
            break;

            case "logo":
            default:
            {
                //int LogoID = DataConvert.CLng(Request.QueryString["LogoID"]);
                //string svgPath = Server.MapPath(iconBll.PlugDir + "assets/icons/" + LogoID + ".svg");
                //SvgDocument svg = SvgDocument.Open(svgPath);
                //Bitmap bmp = svg.Draw();
                //System.Drawing.Image empty = ImgHelper.ReadImgToMS(iconBll.PlugDir + "assets/empty.png");
                //Graphics g = Graphics.FromImage(empty);
                ////SizeF textSize = g.MeasureString(CompName, new Font(""));
                //g.DrawImage(bmp, new Point() { X = 95, Y = 40 });//400,400,商标也固定大小
                //                                                 //添加文字
                //Font mFont = new Font(SelFont("m"), GetFontSize(CompName), FontStyle.Regular);
                //Font sFont = new Font(SelFont("s"), (GetFontSize(SubTitle) / 2), FontStyle.Regular);
                //g.DrawString(CompName, mFont,
                //    new SolidBrush(Color.FromArgb(100, 0, 0, 0)),
                //    GetPosition(empty, g.MeasureString(CompName, mFont), 265));
                //g.DrawString(SubTitle, sFont,
                //    new SolidBrush(Color.FromArgb(100, 102, 102, 102)),
                //    GetPosition(empty, g.MeasureString(SubTitle, sFont), 305 + (int)mFont.Size));
                //empty.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            }
            break;
            }

            //------------
            Response.Cache.SetNoStore();
            Response.ClearContent();
            Response.ContentType = "image/gif";
            Response.BinaryWrite(ms.ToArray());
        }
Ejemplo n.º 6
0
        static FontStore()
        {
            //Regular
            LoadFontVarients("SYSTEM_REGULAR_10", out SYSTEM_REGULAR_10, out SYSTEM_NARROW_10);
            LoadFontVarients("SYSTEM_REGULAR_15", out SYSTEM_REGULAR_15, out SYSTEM_NARROW_15);
            LoadFontVarients("SYSTEM_REGULAR_20", out SYSTEM_REGULAR_20, out SYSTEM_NARROW_20);

            //Bold
            LoadFontVarients("SYSTEM_BOLD_10", out SYSTEM_BOLD_10, out SYSTEM_NARROW_BOLD_10);
            LoadFontVarients("SYSTEM_BOLD_15", out SYSTEM_BOLD_15, out SYSTEM_NARROW_BOLD_15);
            LoadFontVarients("SYSTEM_BOLD_20", out SYSTEM_BOLD_20, out SYSTEM_NARROW_BOLD_20);

            //Misc
            SYSTEM_TALL_BOLD_20 = SYSTEM_BOLD_20.MakeScaledPack(1, 2);
        }
Ejemplo n.º 7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            switch (Action)
            {
            case "text":
            {
                FontPack model = new FontPack().FromJson(Request["model"]);
                if (string.IsNullOrEmpty(model.text))
                {
                    throw new Exception("文字内容不能为空");
                }
                int bmpLen   = 0;
                int maxWidth = 0;                                         //用于list.aspx,不可超过原有的最大宽度
                maxWidth = model.direction == "vertical" ? 0:DataConvert.CLng(Request["width"]);
                int size = GetFontSize(model.text, maxWidth, ref bmpLen); //自动计算出文字大小
                //根据字体,进行一定程度的缩放0.8-1(特殊要求,不可超过原宽度)
                switch (model.family)
                {
                case "architech":
                    size = (int)(size * 0.83);
                    break;

                case "harlow solid italic":
                    size = (int)(size * 0.90);
                    break;
                }
                //"Aileron_Light|BPdotsDiamond|Bauhaus|balloon|architech|belshaw|bpreplay|noodle_script|harlow_solid_italic|arial|arial_narrow|Arial_Rounded_MT_bold"
                //------------------------------------
                //根据方向生成不同的宽度的图片
                Font   mFont = new Font(model.family, size, FontStyle.Regular);
                Bitmap empty = null;
                //有的字体未定义小写字母
                switch (model.direction)
                {
                case "vertical":
                {
                    model.text = model.text.ToUpper();                //垂直下强制大写
                    empty      = new Bitmap((int)(size * 1.5), (int)(bmpLen * 1.3));
                    Graphics g = Graphics.FromImage(empty);
                    g.Clear(Color.FromArgb(0));
                    //每个字为一行
                    char[]     chars = model.text.ToCharArray();
                    SolidBrush brush = new SolidBrush(model.ColorHx16toRGB(model.color)); //Color.FromArgb(100,255,255,255)
                    int        lastY = 0;                                                 //最近一次的Y轴定位
                    for (int i = 0; i < chars.Length; i++)
                    {
                        int    x    = 0;
                        string text = chars[i] + "";
                        //空格不用占过多宽
                        if (text == " ")
                        {
                            lastY += 8; continue;
                        }
                        else if (i == 0)
                        {
                        }
                        else
                        {
                            lastY = lastY + (int)(model.size * 2.5);
                        }
                        //Char.IsLower(chars[i]) ||
                        if (text == "I")
                        {
                            x = model.size / 2;
                        }

                        g.DrawString(text, mFont, brush, new Point(x, lastY));
                    }
                }
                break;

                default:            //
                {
                    //水平下做自动居中处理(即图片宽度不变,前后留空)
                    int bmpWidth = bmpLen;
                    if (maxWidth > 0 && maxWidth > bmpLen)
                    {
                        bmpWidth = maxWidth;
                    }
                    int bmpStart = (int)((bmpWidth - bmpLen) / 2);
                    //throw new Exception(bmpStart + "|" + bmpWidth + "|" + bmpLen);

                    empty = new Bitmap(bmpWidth, (int)(size * 1.5));
                    Graphics g = Graphics.FromImage(empty);
                    //g.Clear(model.ColorHx16toRGB(model.bkcolor));//清除画面,填充背景
                    g.Clear(Color.FromArgb(0));
                    g.DrawString(model.text, mFont,
                                 new SolidBrush(model.ColorHx16toRGB(model.color)),      //Color.FromArgb(100,255,255,255)
                                 new Point(bmpStart, 0));
                }
                break;
                }

                empty.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            }
            break;

            case "logo":
            default:
            {
                //int LogoID = DataConvert.CLng(Request.QueryString["LogoID"]);
                //string svgPath = Server.MapPath(iconBll.PlugDir + "assets/icons/" + LogoID + ".svg");
                //SvgDocument svg = SvgDocument.Open(svgPath);
                //Bitmap bmp = svg.Draw();
                //System.Drawing.Image empty = ImgHelper.ReadImgToMS(iconBll.PlugDir + "assets/empty.png");
                //Graphics g = Graphics.FromImage(empty);
                ////SizeF textSize = g.MeasureString(CompName, new Font(""));
                //g.DrawImage(bmp, new Point() { X = 95, Y = 40 });//400,400,商标也固定大小
                //                                                 //添加文字
                //Font mFont = new Font(SelFont("m"), GetFontSize(CompName), FontStyle.Regular);
                //Font sFont = new Font(SelFont("s"), (GetFontSize(SubTitle) / 2), FontStyle.Regular);
                //g.DrawString(CompName, mFont,
                //    new SolidBrush(Color.FromArgb(100, 0, 0, 0)),
                //    GetPosition(empty, g.MeasureString(CompName, mFont), 265));
                //g.DrawString(SubTitle, sFont,
                //    new SolidBrush(Color.FromArgb(100, 102, 102, 102)),
                //    GetPosition(empty, g.MeasureString(SubTitle, sFont), 305 + (int)mFont.Size));
                //empty.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            }
            break;
            }

            //------------
            Response.Cache.SetNoStore();
            Response.ClearContent();
            Response.ContentType = "image/gif";
            Response.BinaryWrite(ms.ToArray());
        }
Ejemplo n.º 8
0
 private static void LoadFontVarients(string id, out FontPack standard, out FontPack narrow)
 {
     standard = LoadFromResource(id);
     narrow   = standard.MakeScaledPack(0.75f, 1);
 }