示例#1
0
            public FontChar(XmlNode node, FontCommon common)
            {
                kernings = new List <FontKerning>();
                float x = float.Parse(node.Attributes["x"].Value);
                float y = float.Parse(node.Attributes["y"].Value);

                Width    = float.Parse(node.Attributes["width"].Value);
                Height   = float.Parse(node.Attributes["height"].Value);
                XOffset  = float.Parse(node.Attributes["xoffset"].Value);
                YOffset  = float.Parse(node.Attributes["yoffset"].Value);
                XAdvance = float.Parse(node.Attributes["xadvance"].Value);
                //Page        = short.Parse(node.Attributes["page"].Value);
                //Chnl        = short.Parse(node.Attributes["chnl"].Value);
                U  = x / common.ScaleW;
                V  = y / common.ScaleH;
                U2 = U + Width / common.ScaleW;
                V2 = V + Height / common.ScaleH;
            }
示例#2
0
        public override FontFile Handle(string line, FontFile fontFile)
        {
            Dictionary <string, string> dict = CreateDictionary(line, "common");

            var fontCommon = new FontCommon
            {
                LineHeight   = Convert.ToInt32(dict["lineheight"]),
                Base         = Convert.ToInt32(dict["base"]),
                ScaleW       = Convert.ToInt32(dict["scalew"]),
                ScaleH       = Convert.ToInt32(dict["scaleh"]),
                Pages        = Convert.ToInt32(dict["pages"]),
                Packed       = Convert.ToInt32(dict["packed"]),
                AlphaChannel = Convert.ToInt32(dict["alphachnl"]),
                RedChannel   = Convert.ToInt32(dict["redchnl"]),
                GreenChannel = Convert.ToInt32(dict["greenchnl"]),
                BlueChannel  = Convert.ToInt32(dict["bluechnl"])
            };

            fontFile.Common = fontCommon;

            return(fontFile);
        }
示例#3
0
        public FontStyle(string filename)
        {
            XmlDocument spec = new XmlDocument();

            spec.Load(filename);

            //info = new FontInfo(spec.SelectSingleNode("font/info"));
            common = new FontCommon(spec.SelectSingleNode("font/common"));

            XmlNode pagesNode = spec.SelectSingleNode("font/pages");
            XmlNode pageNode  = pagesNode.ChildNodes.Item(0);

            /*int     pageId      = */ int.Parse(pageNode.Attributes["id"].Value);
            string file  = pageNode.Attributes["file"].Value;
            var    image = new RenderStack.Graphics.Image("res/images/" + file);

            texture = new TextureGL(image, false);

            XmlNode charsNode = spec.SelectSingleNode("font/chars");

            foreach (XmlNode charNode in charsNode.ChildNodes)
            {
                int charId = int.Parse(charNode.Attributes["id"].Value);
                chars[charId] = new FontChar(charNode, common);
            }
            XmlNode kerningsNode = spec.SelectSingleNode("font/kernings");

            if (kerningsNode != null)
            {
                foreach (XmlNode kerningNode in kerningsNode.ChildNodes)
                {
                    short first  = short.Parse(kerningNode.Attributes["first"].Value);
                    short second = short.Parse(kerningNode.Attributes["second"].Value);
                    if (first >= 0 && second >= 0 && first < 256 && second < 256)
                    {
                        short amount           = short.Parse(kerningNode.Attributes["amount"].Value);
                        bool  modifiedExisting = false;
                        foreach (FontKerning existingKerning in chars[first].Kernings)
                        {
                            /*  This part is overly paranoid - if unicode wasn't used,  */
                            /*  kerning pairs are broken...  */
                            if (existingKerning.Second == second)
                            {
                                if (
                                    (existingKerning.Amount == 0) ||
                                    (System.Math.Sign(existingKerning.Amount) != System.Math.Sign(amount))
                                    )
                                {
                                    existingKerning.Amount = 0;
                                    break;
                                }
                                if (amount < 0 && amount < existingKerning.Amount)
                                {
                                    existingKerning.Amount = amount;
                                    modifiedExisting       = true;
                                    break;
                                }
                                if (amount > 0 && amount > existingKerning.Amount)
                                {
                                    existingKerning.Amount = amount;
                                    modifiedExisting       = true;
                                    break;
                                }
                            }
                        }
                        if (modifiedExisting == false)
                        {
                            chars[first].Kernings.Add(new FontKerning(second, amount));
                        }
                    }
                }
            }
            else
            {
                System.Diagnostics.Trace.TraceWarning("No kerning info");
            }
            foreach (FontChar @char in chars)
            {
                if (@char != null)
                {
                    if (@char.Kernings != null)
                    {
                        @char.Kernings.Sort();
                    }
                }
            }
        }
示例#4
0
        }// End of function : isNeedSave

        /// <summary>
        /// 获得属性默认值
        /// </summary>
        /// <param name="strName">属性名</param>
        /// <returns>获得属性值</returns>
        public static object GetDefaultValue(string strName)
        {
            switch (strName)
            {
            case ZYTextConst.c_FontName:
                return(ZYEditorControl.GetDefaultSettings(ZYTextConst.c_FontName));

            case ZYTextConst.c_FontSize:
                return(FontCommon.GetFontSizeByName(ZYEditorControl.GetDefaultSettings(ZYTextConst.c_FontSize)));

            case ZYTextConst.c_FontBold:
                return(false);

            case ZYTextConst.c_FontItalic:
                return(false);

            case ZYTextConst.c_FontUnderLine:
                return(false);

            case ZYTextConst.c_ForeColor:
                return(System.Drawing.SystemColors.WindowText);

            case ZYTextConst.c_Sub:
                return(false);

            case ZYTextConst.c_Sup:
                return(false);

            //				case ZYTextConst.c_DeleteTime :
            //					return null;
            case ZYTextConst.c_Deleter:
                return((int)-1);

            case ZYTextConst.c_Creator:
                return((int)0);

            case ZYTextConst.c_SaveList:
                return(true);

            case ZYTextConst.c_Align:
                return(0);

            case ZYTextConst.c_Source:
                return("0000000000");

            case ZYTextConst.c_ListSource:
                return("0000000000");

            case ZYTextConst.c_SaveInFile:
                return(false);

            case ZYTextConst.c_Multiple:
                return(false);

            case ZYTextConst.c_HideTitle:
                return(false);

            case ZYTextConst.c_Height:
                return(1);

            case ZYTextConst.c_NoContent:
                return(false);

            case ZYTextConst.c_TitleLine:
                return(false);

            case ZYTextConst.c_TitleAlign:
                return("left");

            //				case ZYTextConst.c_UnitSource:
            //					return -1 ;
            case ZYTextConst.c_CircleFont:
                return(false);

            default:
                return(null);
            }
        }