Beispiel #1
0
        void AddCharObject(Transform root, CharacterRenderInfo renderInfo, Color color, int order, int x0, int y0)
        {
            Vector2 pos = Vector2.zero;

            pos.x += x0 + renderInfo.x + GetCharacterRenderWidthOffsetX(renderInfo.fontInfo);
            pos.y += y0 + renderInfo.y + renderInfo.fontInfo.OffsetY * TextScale;
            SpriteRenderer rendrer = UtageToolKit.AddChildGameObjectComponent <SpriteRenderer>(root, "" + renderInfo.fontInfo.Char, pos / PixcelsToUnits, Vector2.one * TextScale);

            rendrer.gameObject.hideFlags = HideFlags.DontSave;
            rendrer.material             = Font.Font.material;
            rendrer.sprite           = renderInfo.fontInfo.Sprite;
            rendrer.color            = color;
            rendrer.sortingOrder     = this.OrderInLayer + order;
            rendrer.sortingLayerName = this.SortingLayer;
            if (renderInfo.fontInfo.CharInfo.flipped)
            {
                rendrer.transform.localEulerAngles = new Vector3(0, 0, 90);
            }
            else
            {
                rendrer.transform.localEulerAngles = new Vector3(180, 0, 0);
            }

            renderInfo.AddRenderObj(rendrer.gameObject);
        }
        public virtual void BoundingBoxForRotatedText()
        {
            TextRenderInfo      tri = InitTRI("abc", Math.PI / 2);
            CharacterRenderInfo characterRenderInfo = new CharacterRenderInfo(tri);

            NUnit.Framework.Assert.IsTrue(characterRenderInfo.GetBoundingBox().EqualsWithEpsilon(new Rectangle(-8.616f
                                                                                                               , 0f, 11.1f, 19.344f)));
        }
Beispiel #3
0
 //行末の禁則文字のチェック
 bool CheckKinsokuEnd(CharacterRenderInfo info)
 {
     if (info == null)
     {
         return(false);
     }
     if (info.charInfo == null)
     {
         return(false);
     }
     return(kinsokuEnd.IndexOf(info.charInfo.Char) >= 0);
 }
Beispiel #4
0
        //WordWrap処理
        int ParseWordWrap(List <CharacterRenderInfo> infoList, int index)
        {
            CharacterRenderInfo current = infoList[index];                          //はみ出た文字
            CharacterRenderInfo prev    = (index > 0) ? infoList[index - 1] : null; //一つ前の文字

            if (CheckWordWrap(current, prev))
            {                   //禁則に引っかかるので、一文字前をチェック
                return(ParseWordWrap(infoList, index - 1));
            }
            else
            {
                return(index);
            }
        }
Beispiel #5
0
        //英単語のワードラップチェック(行頭)
        bool CheckWordWrapDefaultTop(CharacterRenderInfo info)
        {
            if (info == null)
            {
                return(false);
            }
            if (info.charInfo == null)
            {
                return(false);
            }

            char c = info.charInfo.Char;

            return(UtageToolKit.IsHankaku(c) && !char.IsSeparator(c));
        }
Beispiel #6
0
        //禁則処理文字のチェック
        bool CheckWordWrap(CharacterRenderInfo current, CharacterRenderInfo prev)
        {
            bool ret = false;

            if ((WordWrapType & WordWrap.Default) == WordWrap.Default)
            {
                ret |= CheckWordWrapDefaultEnd(prev) && CheckWordWrapDefaultTop(current);
            }

            if ((WordWrapType & WordWrap.JapaneseKinsoku) == WordWrap.JapaneseKinsoku)
            {
                ret |= (CheckKinsokuEnd(prev) || CheckKinsokuTop(current));
            }

            return(ret);
        }
Beispiel #7
0
        //自動改行
        //禁則などで送り出しされる文字がある場合は、改行可能な位置まで文字を削除していく
        void AutoLineBreak(List <CharacterRenderInfo> infoList)
        {
            int index = infoList.Count - 1;

            CharacterRenderInfo current = infoList[index];                          //はみ出た文字
            CharacterRenderInfo prev    = (index > 0) ? infoList[index - 1] : null; //一つ前の文字

            if (null == current || null == prev)
            {                   //そのまま
            }
            else if (CheckKinsokuBurasage(current))
            {                   //ぶら下げ文字
                current.isKinsokuBurasage = true;
            }
            else if (prev.IsBr)
            {
                //前の文字が改行の場合、そのまま
            }
            else if (CheckWordWrap(current, prev))
            {                   //禁則処理
                                //改行可能な位置まで文字を削除していく
                int i     = ParseWordWrap(infoList, index - 1) - 1;
                int count = (index - i);
                if (count > 0)
                {
                    infoList[i].isAutoLineBreak = true;
                    infoList.RemoveRange(i + 1, count);
                }
            }
            else
            {
                //前の文字を自動改行して
                prev.isAutoLineBreak = true;
                infoList.Remove(current);
            }
        }
Beispiel #8
0
        //Layoutによる位置の調整
        void MoveLayout(float y, List <CharacterRenderInfo> infoList)
        {
            //LayoutによってX位置の調整
            int index = 0;

            while (index < infoList.Count)
            {
                float w     = 0;
                int   begin = index;
                int   end   = index;
                for (int i = begin; i < infoList.Count; ++i)
                {
                    CharacterRenderInfo info = infoList[i];
                    w   = info.x + info.w;
                    end = i;
                    if (info.IsBr)
                    {
                        break;
                    }
                }
                float offsetX = ToLayoutOffsetX(w);
                for (int i = begin; i <= end; ++i)
                {
                    infoList[i].x += offsetX;
                }
                index = end + 1;
            }

            float offsetY = Size / 2;                           //フォントを座標の中央表示するため

            offsetY += ToLayoutOffsetY(y);                      //LayoutによってY位置の調整
            foreach (var item in infoList)
            {
                item.y += offsetY;
            }
        }
Beispiel #9
0
        //各文字の描画データを作成
        List <CharacterRenderInfo> CreateRenderInfo(TextData textData)
        {
            List <CharacterRenderInfo> infoList = new List <CharacterRenderInfo>();

            if (textData == null)
            {
                return(infoList);
            }

            float y            = -Size;
            bool  isOverHeight = false;

            while (infoList.Count < textData.Length && !isOverHeight)
            {
                float x = 0;
                while (infoList.Count < textData.Length)
                {
                    CharData       c               = textData.CharList[infoList.Count];
                    FontRenderInfo renderInfo      = null;
                    float          w               = 0;
                    bool           isAutoLineBreak = false;
                    if (c.IsBr)
                    {
                    }
                    else if (char.IsWhiteSpace(c.Char))
                    {
                        w = Space;
                    }
                    else
                    {
                        renderInfo = Font.GetRenderInfoCreateIfMissing(c.Char, pixcelsToUnits);
                        if (renderInfo != null)
                        {
                            w = GetCharacterRenderWidth(renderInfo);
                            //横幅を越えるなら自動改行
                            isAutoLineBreak = IsOverMaxWidth(x, w);
                        }
                    }
                    //文字の追加
                    CharacterRenderInfo charInfo = new CharacterRenderInfo(c, renderInfo, x, y, w, isAutoLineBreak);
                    infoList.Add(charInfo);
                    x += w + LetterSpace;
                    //改行処理
                    if (charInfo.IsBr)
                    {
                        if (isAutoLineBreak)
                        {
                            //自動改行
                            AutoLineBreak(infoList);
                        }
                        float offsetY = -(LineSpace + Size);
                        //縦幅のチェック
                        if (IsOverMaxHeight(y + offsetY))
                        {
                            isOverHeight = true;
                        }
                        else
                        {
                            y += offsetY;
                        }
                        break;
                    }
                }
            }

            MoveLayout(y, infoList);
            return(infoList);
        }
		void AddCharObject(Transform root, CharacterRenderInfo renderInfo, Color color, int order, int x0, int y0)
		{
			Vector2 pos = Vector2.zero;
			pos.x += x0 + renderInfo.x + GetCharacterRenderWidthOffsetX(renderInfo.fontInfo);
			pos.y += y0 + renderInfo.y + renderInfo.fontInfo.OffsetY * TextScale;
			SpriteRenderer rendrer = UtageToolKit.AddChildGameObjectComponent<SpriteRenderer>(root, "" + renderInfo.fontInfo.Char, pos / PixcelsToUnits, Vector2.one * TextScale);
			rendrer.gameObject.hideFlags = HideFlags.DontSave;
			rendrer.material = Font.Font.material;
			rendrer.sprite = renderInfo.fontInfo.Sprite;
			rendrer.color = color;
			rendrer.sortingOrder = this.OrderInLayer + order;
			rendrer.sortingLayerName = this.SortingLayer;

			rendrer.transform.localEulerAngles = WrapperUnityVersion.GetFontSpriteAngles(renderInfo.fontInfo );

			renderInfo.AddRenderObj(rendrer.gameObject);
		}
		//行末の禁則文字のチェック
		bool CheckKinsokuEnd(CharacterRenderInfo info)
		{
			if (info == null) return false;
			if (info.charInfo == null) return false;
			return (kinsokuEnd.IndexOf(info.charInfo.Char) >= 0);
		}
//		string kinsokuBurasage = "、。";						//ぶら下げ組み文字

		//ぶら下げ文字のチェック
		bool CheckKinsokuBurasage(CharacterRenderInfo c)
		{
			return false;
		}
		//英単語のワードラップチェック(行頭)
		bool CheckWordWrapDefaultTop(CharacterRenderInfo info)
		{
			if (info == null) return false;
			if (info.charInfo == null) return false;

			char c = info.charInfo.Char;
			return UtageToolKit.IsHankaku(c) && !char.IsSeparator(c);
		}
		//禁則処理文字のチェック
		bool CheckWordWrap(CharacterRenderInfo current, CharacterRenderInfo prev)
		{
			bool ret = false;
			if ((WordWrapType & WordWrap.Default) == WordWrap.Default)
			{
				ret |= CheckWordWrapDefaultEnd(prev) && CheckWordWrapDefaultTop(current);
			}

			if ((WordWrapType & WordWrap.JapaneseKinsoku) == WordWrap.JapaneseKinsoku)
			{
				ret |= (CheckKinsokuEnd(prev) || CheckKinsokuTop(current));
			}

			return ret;
		}
		//各文字の描画データを作成
		List<CharacterRenderInfo> CreateRenderInfo(TextData textData)
		{

			List<CharacterRenderInfo> infoList = new List<CharacterRenderInfo>();
			if (textData == null) return infoList;

			float y = -Size;
			bool isOverHeight = false;
			while (infoList.Count < textData.Length && !isOverHeight)
			{
				float x = 0;
				while (infoList.Count < textData.Length)
				{
					CharData c = textData.CharList[infoList.Count];
					FontRenderInfo renderInfo = null;
					float w = 0;
					bool isAutoLineBreak = false;
					if (c.IsBr)
					{
					}
					else if (char.IsWhiteSpace(c.Char))
					{
						w = Space;
					}
					else
					{
						renderInfo = Font.GetRenderInfoCreateIfMissing(c.Char,pixcelsToUnits);
						if (renderInfo != null)
						{
							w = GetCharacterRenderWidth(renderInfo);
							//横幅を越えるなら自動改行
							isAutoLineBreak = IsOverMaxWidth(x, w);
						}
					}
					//文字の追加
					CharacterRenderInfo charInfo = new CharacterRenderInfo(c, renderInfo, x, y, w, isAutoLineBreak);
					infoList.Add(charInfo);
					x += w + LetterSpace;
					//改行処理
					if (charInfo.IsBr)
					{
						if (isAutoLineBreak)
						{
							//自動改行
							AutoLineBreak(infoList);
						}
						float offsetY = -(LineSpace + Size);
						//縦幅のチェック
						if (IsOverMaxHeight(y + offsetY))
						{
							isOverHeight = true;
						}
						else
						{
							y += offsetY;
						}
						break;
					}
				}
			}

			MoveLayout(y, infoList);
			return infoList;
		}
Beispiel #16
0
//		string kinsokuBurasage = "、。";						//ぶら下げ組み文字

        //ぶら下げ文字のチェック
        bool CheckKinsokuBurasage(CharacterRenderInfo c)
        {
            return(false);
        }
Beispiel #17
0
 //文字表示オブジェクト追加
 void AddCharObject(Transform root, CharacterRenderInfo renderInfo, Color color, int order)
 {
     AddCharObject(root, renderInfo, color, order, 0, 0);
 }
		//文字表示オブジェクト追加
		void AddCharObject(Transform root, CharacterRenderInfo renderInfo, Color color, int order)
		{
			AddCharObject(root, renderInfo, color, order, 0, 0);
		}