AddChar() public method

public AddChar ( char ch, BMGlyph glyph ) : void
ch char
glyph BMGlyph
return void
 static public int AddChar(IntPtr l)
 {
     try {
         FairyGUI.BitmapFont self = (FairyGUI.BitmapFont)checkSelf(l);
         System.Char         a1;
         checkType(l, 2, out a1);
         FairyGUI.BitmapFont.BMGlyph a2;
         checkType(l, 3, out a2);
         self.AddChar(a1, a2);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Esempio n. 2
0
        BitmapFont LoadFont(PackageItem item)
        {
            BitmapFont font = new BitmapFont(UIPackage.URL_PREFIX + this.id + item.id);

            string str = GetDesc(item.id + ".fnt");
            string[] arr = str.Split(sep1);
            int cnt = arr.Length;
            Dictionary<string, string> kv = new Dictionary<string, string>();
            NTexture mainTexture = null;
            Vector2 atlasOffset = new Vector2();
            bool ttf = false;
            int lineHeight = 0;
            int xadvance = 0;

            for (int i = 0; i < cnt; i++)
            {
                str = arr[i];
                if (str.Length == 0)
                    continue;

                str = str.Trim();

                string[] arr2 = str.Split(sep2, StringSplitOptions.RemoveEmptyEntries);
                for (int j = 1; j < arr2.Length; j++)
                {
                    string[] arr3 = arr2[j].Split(sep3, StringSplitOptions.RemoveEmptyEntries);
                    kv[arr3[0]] = arr3[1];
                }

                str = arr2[0];
                if (str == "char")
                {
                    BitmapFont.BMGlyph bg = new BitmapFont.BMGlyph();
                    if (kv.TryGetValue("x", out str))
                        bg.x = int.Parse(str);
                    if (kv.TryGetValue("y", out str))
                        bg.y = int.Parse(str);
                    if (kv.TryGetValue("xoffset", out str))
                        bg.offsetX = int.Parse(str);
                    if (kv.TryGetValue("yoffset", out str))
                        bg.offsetY = int.Parse(str);
                    if (kv.TryGetValue("width", out str))
                        bg.width = int.Parse(str);
                    if (kv.TryGetValue("height", out str))
                        bg.height = int.Parse(str);
                    if (kv.TryGetValue("xadvance", out str))
                        bg.advance = int.Parse(str);
                    if (kv.TryGetValue("chnl", out str))
                    {
                        bg.channel = int.Parse(str);
                        if (bg.channel == 15)
                            bg.channel = 4;
                        else if (bg.channel == 1)
                            bg.channel = 3;
                        else if (bg.channel == 2)
                            bg.channel = 2;
                        else
                            bg.channel = 1;
                    }

                    if (!ttf)
                    {
                        if (kv.TryGetValue("img", out str))
                        {
                            PackageItem charImg;
                            if (_itemsById.TryGetValue(str, out charImg))
                            {
                                charImg.Load();
                                bg.uvRect = charImg.texture.uvRect;
                                if (mainTexture == null)
                                    mainTexture = charImg.texture.root;
                                bg.width = charImg.texture.width;
                                bg.height = charImg.texture.height;
                            }
                        }
                    }
                    else
                    {
                        Rect region = new Rect(bg.x + atlasOffset.x, bg.y + atlasOffset.y, bg.width, bg.height);
                        bg.uvRect = new Rect(region.x / mainTexture.width, 1 - region.yMax / mainTexture.height,
                            region.width / mainTexture.width, region.height / mainTexture.height);
                    }

                    if (ttf)
                        bg.lineHeight = lineHeight;
                    else
                    {
                        if (bg.advance == 0)
                        {
                            if (xadvance == 0)
                                bg.advance = bg.offsetX + bg.width;
                            else
                                bg.advance = xadvance;
                        }

                        bg.lineHeight = bg.offsetY < 0 ? bg.height : (bg.offsetY + bg.height);
                        if (bg.lineHeight < lineHeight)
                            bg.lineHeight = lineHeight;
                    }

                    int ch = int.Parse(kv["id"]);
                    font.AddChar((char)ch, bg);
                }
                else if (str == "info")
                {
                    if (kv.TryGetValue("face", out str))
                    {
                        ttf = true;

                        AtlasSprite sprite;
                        if (_sprites.TryGetValue(item.id, out sprite))
                        {
                            atlasOffset = new Vector2(sprite.rect.x, sprite.rect.y);
                            PackageItem atlasItem = _itemsById[sprite.atlas];
                            mainTexture = (NTexture)GetItemAsset(atlasItem);
                        }
                    }
                }
                else if (str == "common")
                {
                    if (kv.TryGetValue("lineHeight", out str))
                        lineHeight = int.Parse(str);
                    if (kv.TryGetValue("xadvance", out str))
                        xadvance = int.Parse(str);
                }
            }

            font.hasChannel = ttf;
            font.canTint = ttf;
            font.lineHeight = lineHeight;
            font.mainTexture = mainTexture;
            if (!ttf)
            {
                if (mainTexture != null && mainTexture.root.alphaTexture != null)
                    font.shader = ShaderConfig.combinedImageShader;
                else
                    font.shader = ShaderConfig.imageShader;
            }
            return font;
        }
Esempio n. 3
0
        void LoadFont(PackageItem item)
        {
            BitmapFont font = new BitmapFont(item);

            item.bitmapFont = font;
            ByteBuffer buffer = item.rawData;

            buffer.Seek(0, 0);

            bool ttf = buffer.ReadBool();

            font.colorEnabled = buffer.ReadBool();
            font.scaleEnabled = buffer.ReadBool();
            buffer.ReadBool();            //hasChannel
            int fontSize   = buffer.ReadInt();
            int xadvance   = buffer.ReadInt();
            int lineHeight = buffer.ReadInt();

            float       texScaleX   = 1;
            float       texScaleY   = 1;
            NTexture    mainTexture = null;
            AtlasSprite mainSprite  = null;

            if (ttf && _sprites.TryGetValue(item.id, out mainSprite))
            {
                mainTexture = (NTexture)GetItemAsset(mainSprite.atlas);
                texScaleX   = mainTexture.root.uvRect.Width / mainTexture.width;
                texScaleY   = mainTexture.root.uvRect.Height / mainTexture.height;
            }

            buffer.Seek(0, 1);

            BitmapFont.BMGlyph bg;
            int cnt = buffer.ReadInt();

            for (int i = 0; i < cnt; i++)
            {
                int nextPos = buffer.ReadShort();
                nextPos += buffer.position;

                bg = new BitmapFont.BMGlyph();
                char ch = buffer.ReadChar();
                font.AddChar(ch, bg);

                string img = buffer.ReadS();
                int    bx  = buffer.ReadInt();
                int    by  = buffer.ReadInt();
                bg.offsetX = buffer.ReadInt();
                bg.offsetY = buffer.ReadInt();
                bg.width   = buffer.ReadInt();
                bg.height  = buffer.ReadInt();
                bg.advance = buffer.ReadInt();
                bg.channel = buffer.ReadByte();
                if (bg.channel == 1)
                {
                    bg.channel = 3;
                }
                else if (bg.channel == 2)
                {
                    bg.channel = 2;
                }
                else if (bg.channel == 3)
                {
                    bg.channel = 1;
                }

                if (ttf)
                {
                    if (mainSprite.rotated)
                    {
                        bg.uv[0] = new Vector2((float)(by + bg.height + mainSprite.rect.X) * texScaleX,
                                               1 - (float)(mainSprite.rect.Bottom - bx) * texScaleY);
                        bg.uv[1] = new Vector2(bg.uv[0].X - (float)bg.height * texScaleX, bg.uv[0].Y);
                        bg.uv[2] = new Vector2(bg.uv[1].X, bg.uv[0].Y + (float)bg.width * texScaleY);
                        bg.uv[3] = new Vector2(bg.uv[0].X, bg.uv[2].Y);
                    }
                    else
                    {
                        bg.uv[0] = new Vector2((float)(bx + mainSprite.rect.X) * texScaleX,
                                               1 - (float)(by + bg.height + mainSprite.rect.Y) * texScaleY);
                        bg.uv[1] = new Vector2(bg.uv[0].X, bg.uv[0].Y + (float)bg.height * texScaleY);
                        bg.uv[2] = new Vector2(bg.uv[0].X + (float)bg.width * texScaleX, bg.uv[1].Y);
                        bg.uv[3] = new Vector2(bg.uv[2].X, bg.uv[0].Y);
                    }

                    bg.lineHeight = lineHeight;
                }
                else
                {
                    PackageItem charImg;
                    if (_itemsById.TryGetValue(img, out charImg))
                    {
                        GetItemAsset(charImg);
                        charImg.texture.GetUV(bg.uv);
                        bg.width  = charImg.texture.width;
                        bg.height = charImg.texture.height;

                        if (mainTexture == null)
                        {
                            mainTexture = charImg.texture.root;
                        }
                    }

                    if (fontSize == 0)
                    {
                        fontSize = bg.height;
                    }

                    if (bg.advance == 0)
                    {
                        if (xadvance == 0)
                        {
                            bg.advance = bg.offsetX + bg.width;
                        }
                        else
                        {
                            bg.advance = xadvance;
                        }
                    }

                    bg.lineHeight = bg.offsetY < 0 ? bg.height : (bg.offsetY + bg.height);
                    if (bg.lineHeight < font.size)
                    {
                        bg.lineHeight = font.size;
                    }
                }

                buffer.position = nextPos;
            }

            font.size        = fontSize;
            font.mainTexture = mainTexture;
        }
Esempio n. 4
0
        void LoadFont(PackageItem item)
        {
            BitmapFont font = new BitmapFont(item);

            item.bitmapFont = font;
            ByteBuffer buffer = item.rawData;

            buffer.Seek(0, 0);

            bool ttf = buffer.ReadBool();

            font.canTint    = buffer.ReadBool();
            font.resizable  = buffer.ReadBool();
            font.hasChannel = buffer.ReadBool();
            int fontSize   = buffer.ReadInt();
            int xadvance   = buffer.ReadInt();
            int lineHeight = buffer.ReadInt();

            float       texScaleX   = 1;
            float       texScaleY   = 1;
            NTexture    mainTexture = null;
            AtlasSprite mainSprite  = null;

            if (ttf && _sprites.TryGetValue(item.id, out mainSprite))
            {
                mainTexture = (NTexture)GetItemAsset(mainSprite.atlas);
                texScaleX   = mainTexture.root.uvRect.width / mainTexture.width;
                texScaleY   = mainTexture.root.uvRect.height / mainTexture.height;
            }

            buffer.Seek(0, 1);

            BitmapFont.BMGlyph bg;
            int cnt = buffer.ReadInt();

            for (int i = 0; i < cnt; i++)
            {
                int nextPos = buffer.ReadShort();
                nextPos += buffer.position;

                bg = new BitmapFont.BMGlyph();
                char ch = buffer.ReadChar();
                font.AddChar(ch, bg);

                string img = buffer.ReadS();
                int    bx  = buffer.ReadInt();
                int    by  = buffer.ReadInt();
                bg.offsetX = buffer.ReadInt();
                bg.offsetY = buffer.ReadInt();
                bg.width   = buffer.ReadInt();
                bg.height  = buffer.ReadInt();
                bg.advance = buffer.ReadInt();
                bg.channel = buffer.ReadByte();
                if (bg.channel == 1)
                {
                    bg.channel = 3;
                }
                else if (bg.channel == 2)
                {
                    bg.channel = 2;
                }
                else if (bg.channel == 3)
                {
                    bg.channel = 1;
                }

                if (ttf)
                {
                    if (mainSprite.rotated)
                    {
                        bg.uv[0] = new Vector2((float)(by + bg.height + mainSprite.rect.x) * texScaleX,
                                               1 - (float)(mainSprite.rect.yMax - bx) * texScaleY);
                        bg.uv[1] = new Vector2(bg.uv[0].x - (float)bg.height * texScaleX, bg.uv[0].y);
                        bg.uv[2] = new Vector2(bg.uv[1].x, bg.uv[0].y + (float)bg.width * texScaleY);
                        bg.uv[3] = new Vector2(bg.uv[0].x, bg.uv[2].y);
                    }
                    else
                    {
                        bg.uv[0] = new Vector2((float)(bx + mainSprite.rect.x) * texScaleX,
                                               1 - (float)(by + bg.height + mainSprite.rect.y) * texScaleY);
                        bg.uv[1] = new Vector2(bg.uv[0].x, bg.uv[0].y + (float)bg.height * texScaleY);
                        bg.uv[2] = new Vector2(bg.uv[0].x + (float)bg.width * texScaleX, bg.uv[1].y);
                        bg.uv[3] = new Vector2(bg.uv[2].x, bg.uv[0].y);
                    }

                    bg.lineHeight = lineHeight;
                }
                else
                {
                    PackageItem charImg;
                    if (_itemsById.TryGetValue(img, out charImg))
                    {
                        GetItemAsset(charImg);
                        Rect uvRect = charImg.texture.uvRect;
                        bg.uv[0] = uvRect.position;
                        bg.uv[1] = new Vector2(uvRect.xMin, uvRect.yMax);
                        bg.uv[2] = new Vector2(uvRect.xMax, uvRect.yMax);
                        bg.uv[3] = new Vector2(uvRect.xMax, uvRect.yMin);
                        if (charImg.texture.rotated)
                        {
                            NGraphics.RotateUV(bg.uv, ref uvRect);
                        }
                        bg.width  = charImg.texture.width;
                        bg.height = charImg.texture.height;

                        if (mainTexture == null)
                        {
                            mainTexture = charImg.texture.root;
                        }
                    }

                    if (fontSize == 0)
                    {
                        fontSize = bg.height;
                    }

                    if (bg.advance == 0)
                    {
                        if (xadvance == 0)
                        {
                            bg.advance = bg.offsetX + bg.width;
                        }
                        else
                        {
                            bg.advance = xadvance;
                        }
                    }

                    bg.lineHeight = bg.offsetY < 0 ? bg.height : (bg.offsetY + bg.height);
                    if (bg.lineHeight < font.size)
                    {
                        bg.lineHeight = font.size;
                    }
                }

                buffer.position = nextPos;
            }

            font.size        = fontSize;
            font.mainTexture = mainTexture;
            if (!font.hasChannel)
            {
                font.shader = ShaderConfig.imageShader;
            }
        }
Esempio n. 5
0
		void LoadFont(PackageItem item)
		{
			BitmapFont font = item.bitmapFont;

			string str = _descPack[item.id + ".fnt"];
			string[] arr = str.Split('\n');
			int cnt = arr.Length;
			Dictionary<string, string> kv = new Dictionary<string, string>();
			NTexture mainTexture = null;
			Vector2 atlasOffset = new Vector2();
			bool ttf = false;
			int size = 0;
			int xadvance = 0;
			bool resizable = false;
			bool canTint = false;
			bool hasFullChannel = false;
			int lineHeight = 0;
			BitmapFont.BMGlyph bg = null;

			char[] splitter0 = new char[] { ' ' };
			char[] splitter1 = new char[] { '=' };

			for (int i = 0; i < cnt; i++)
			{
				str = arr[i];
				if (str.Length == 0)
					continue;

				str = str.Trim();

				string[] arr2 = str.Split(splitter0, StringSplitOptions.RemoveEmptyEntries);
				for (int j = 1; j < arr2.Length; j++)
				{
					string[] arr3 = arr2[j].Split(splitter1, StringSplitOptions.RemoveEmptyEntries);
					kv[arr3[0]] = arr3[1];
				}

				str = arr2[0];
				if (str == "char")
				{
					bg = new BitmapFont.BMGlyph();
					int bx = 0, by = 0;
					if (kv.TryGetValue("x", out str))
						bx = int.Parse(str);
					if (kv.TryGetValue("y", out str))
						by = int.Parse(str);
					if (kv.TryGetValue("xoffset", out str))
						bg.offsetX = int.Parse(str);
					if (kv.TryGetValue("yoffset", out str))
						bg.offsetY = int.Parse(str);
					if (kv.TryGetValue("width", out str))
						bg.width = int.Parse(str);
					if (kv.TryGetValue("height", out str))
						bg.height = int.Parse(str);
					if (kv.TryGetValue("xadvance", out str))
						bg.advance = int.Parse(str);
					if (kv.TryGetValue("chnl", out str))
					{
						bg.channel = int.Parse(str);
						if (bg.channel == 1)
							bg.channel = 3;
						else if (bg.channel == 2)
							bg.channel = 2;
						else if (bg.channel == 3)
							bg.channel = 1;
						else
							hasFullChannel = true;
					}
					else
						hasFullChannel = true;

					if (!ttf)
					{
						if (kv.TryGetValue("img", out str))
						{
							PackageItem charImg;
							if (_itemsById.TryGetValue(str, out charImg))
							{
								GetItemAsset(charImg);
								bg.uvRect = charImg.texture.uvRect;
								if (mainTexture == null)
									mainTexture = charImg.texture.root;
								bg.width = charImg.texture.width;
								bg.height = charImg.texture.height;
							}
						}
					}
					else
					{
						Rect region = new Rect(bx + atlasOffset.x, by + atlasOffset.y, bg.width, bg.height);
						bg.uvRect = new Rect(region.x / mainTexture.width, 1 - region.yMax / mainTexture.height,
							region.width / mainTexture.width, region.height / mainTexture.height);
					}

					if (ttf)
						bg.lineHeight = lineHeight;
					else
					{
						if (bg.advance == 0)
						{
							if (xadvance == 0)
								bg.advance = bg.offsetX + bg.width;
							else
								bg.advance = xadvance;
						}

						bg.lineHeight = bg.offsetY < 0 ? bg.height : (bg.offsetY + bg.height);
						if (bg.lineHeight < size)
							bg.lineHeight = size;
					}

					int ch = int.Parse(kv["id"]);
					font.AddChar((char)ch, bg);
				}
				else if (str == "info")
				{
					if (kv.TryGetValue("face", out str))
					{
						ttf = true;
						canTint = true;

						AtlasSprite sprite;
						if (_sprites.TryGetValue(item.id, out sprite))
						{
							atlasOffset = new Vector2(sprite.rect.x, sprite.rect.y);
							PackageItem atlasItem = _itemsById[sprite.atlas];
							mainTexture = (NTexture)GetItemAsset(atlasItem);
						}
					}
					if (kv.TryGetValue("size", out str))
						size = int.Parse(str);
					if (kv.TryGetValue("resizable", out str))
						resizable = str == "true";
					if (kv.TryGetValue("colored", out str))
						canTint = str == "true";

					if (size == 0)
						size = lineHeight;
					else if (lineHeight == 0)
						lineHeight = size;
				}
				else if (str == "common")
				{
					if (kv.TryGetValue("lineHeight", out str))
						lineHeight = int.Parse(str);
					if (kv.TryGetValue("xadvance", out str))
						xadvance = int.Parse(str);
				}
			}

			if (size == 0 && bg != null)
				size = bg.height;

			font.hasChannel = ttf;
			font.canTint = canTint;
			font.size = size;
			font.resizable = resizable;
			font.mainTexture = mainTexture;
			if (!ttf || hasFullChannel)
				font.shader = ShaderConfig.imageShader;
		}
Esempio n. 6
0
        BitmapFont LoadFont(PackageItem item)
        {
            BitmapFont font = new BitmapFont(URL_PREFIX + this.id + item.id);

            string str = GetDesc(item.id + ".fnt");

            string[] arr = str.Split(sep1);
            int      cnt = arr.Length;
            Dictionary <string, string> kv = new Dictionary <string, string>();
            NTexture mainTexture           = null;
            Vector2  atlasOffset           = new Vector2();
            bool     ttf        = false;
            int      lineHeight = 0;
            int      xadvance   = 0;

            for (int i = 0; i < cnt; i++)
            {
                str = arr[i];
                if (str.Length == 0)
                {
                    continue;
                }

                str = str.Trim();

                string[] arr2 = str.Split(sep2, StringSplitOptions.RemoveEmptyEntries);
                for (int j = 1; j < arr2.Length; j++)
                {
                    string[] arr3 = arr2[j].Split(sep3, StringSplitOptions.RemoveEmptyEntries);
                    kv[arr3[0]] = arr3[1];
                }

                str = arr2[0];
                if (str == "char")
                {
                    BitmapFont.BMGlyph bg = new BitmapFont.BMGlyph();
                    if (kv.TryGetValue("x", out str))
                    {
                        bg.x = int.Parse(str);
                    }
                    if (kv.TryGetValue("y", out str))
                    {
                        bg.y = int.Parse(str);
                    }
                    if (kv.TryGetValue("xoffset", out str))
                    {
                        bg.offsetX = int.Parse(str);
                    }
                    if (kv.TryGetValue("yoffset", out str))
                    {
                        bg.offsetY = int.Parse(str);
                    }
                    if (kv.TryGetValue("width", out str))
                    {
                        bg.width = int.Parse(str);
                    }
                    if (kv.TryGetValue("height", out str))
                    {
                        bg.height = int.Parse(str);
                    }
                    if (kv.TryGetValue("xadvance", out str))
                    {
                        bg.advance = int.Parse(str);
                    }
                    if (kv.TryGetValue("chnl", out str))
                    {
                        bg.channel = int.Parse(str);
                        if (bg.channel == 15)
                        {
                            bg.channel = 4;
                        }
                        else if (bg.channel == 1)
                        {
                            bg.channel = 3;
                        }
                        else if (bg.channel == 2)
                        {
                            bg.channel = 2;
                        }
                        else
                        {
                            bg.channel = 1;
                        }
                    }

                    if (!ttf)
                    {
                        if (kv.TryGetValue("img", out str))
                        {
                            PackageItem charImg;
                            if (_itemsById.TryGetValue(str, out charImg))
                            {
                                charImg.Load();
                                bg.uvRect = charImg.texture.uvRect;
                                if (mainTexture == null)
                                {
                                    mainTexture = charImg.texture.root;
                                }
                                bg.width  = charImg.texture.width;
                                bg.height = charImg.texture.height;
                            }
                        }
                    }
                    else
                    {
                        Rect region = new Rect(bg.x + atlasOffset.x, bg.y + atlasOffset.y, bg.width, bg.height);
                        bg.uvRect = new Rect(region.x / mainTexture.width, 1 - region.yMax / mainTexture.height,
                                             region.width / mainTexture.width, region.height / mainTexture.height);
                    }

                    if (ttf)
                    {
                        bg.lineHeight = lineHeight;
                    }
                    else
                    {
                        if (bg.advance == 0)
                        {
                            if (xadvance == 0)
                            {
                                bg.advance = bg.offsetX + bg.width;
                            }
                            else
                            {
                                bg.advance = xadvance;
                            }
                        }

                        bg.lineHeight = bg.offsetY < 0 ? bg.height : (bg.offsetY + bg.height);
                        if (bg.lineHeight < lineHeight)
                        {
                            bg.lineHeight = lineHeight;
                        }
                    }

                    int ch = int.Parse(kv["id"]);
                    font.AddChar((char)ch, bg);
                }
                else if (str == "info")
                {
                    if (kv.TryGetValue("face", out str))
                    {
                        ttf = true;

                        AtlasSprite sprite;
                        if (_sprites.TryGetValue(item.id, out sprite))
                        {
                            atlasOffset = new Vector2(sprite.rect.x, sprite.rect.y);
                            PackageItem atlasItem = _itemsById[sprite.atlas];
                            mainTexture = (NTexture)GetItemAsset(atlasItem);
                        }
                    }
                }
                else if (str == "common")
                {
                    if (kv.TryGetValue("lineHeight", out str))
                    {
                        lineHeight = int.Parse(str);
                    }
                    if (kv.TryGetValue("xadvance", out str))
                    {
                        xadvance = int.Parse(str);
                    }
                }
            }

            font.hasChannel  = ttf;
            font.canTint     = ttf;
            font.lineHeight  = lineHeight;
            font.mainTexture = mainTexture;
            if (!ttf)
            {
                if (mainTexture != null && mainTexture.root.alphaTexture != null)
                {
                    font.shader = ShaderConfig.combinedImageShader;
                }
                else
                {
                    font.shader = ShaderConfig.imageShader;
                }
            }
            return(font);
        }