예제 #1
0
        // 座標は変換後。Yは上がプラス!
        private void AddTextVerticalSingleLine(
            string text,
            float left,
            float top,
            float width,
            float height,
            float scale,
            bool leftAlign)
        {
            int letterCount = text.Length;
            // x,yを置換してレイアウトさせる
            LayoutState layout = new LayoutState();

            layout.Initialize(_font, height, width, scale, leftAlign);
            float ascent = (float)(_font.ascent) * scale;

            int   i     = (leftAlign) ? 0 : (letterCount - 1);
            int   endI  = (leftAlign) ? letterCount : -1;
            int   di    = (leftAlign) ? 1 : -1;
            float right = left + width;

            while (i != endI)
            {
                CharacterInfo ch;
                char          c = text[i];
                if (c == '\t')
                {
                    c = ' ';
                }

                if (c == '\n')
                {
                    break;
                }
                else if (_font.GetCharacterInfo(c, out ch) == true)
                {
                    if (layout.TryPut(ref ch) == false)
                    {
                        break;
                    }

                    if (leftAlign == false)
                    {
                        layout.Put(ref ch);
                    }

                    // x,yを入れ換えている
                    if (AddCharRotated(
                            right - layout.y - ascent,
                            top - layout.x,
                            scale,
                            ref ch) == false)
                    {
                        break;
                    }

                    if (leftAlign)
                    {
                        layout.Put(ref ch);
                    }
                }
                i += di;
            }
        }
예제 #2
0
        // 座標は変換後。Yは上がプラス!
        private void AddTextHorizontalMultiLine(
            string text,
            float left,
            float top,
            float width,
            float height,
            float scale,
            bool autoLineBreak,
            float lineHeight)
        {
            int letterCount = text.Length;

            if (letterCount == 0)
            {
                return;
            }
            LayoutState layout = new LayoutState();

            layout.Initialize(_font, width, height, scale, true, lineHeight);
            float ascent = (float)(_font.ascent) * scale;

            for (int i = 0; i < letterCount; i++)
            {
                CharacterInfo ch;
                // 改行検出
                char c = text[i];
                if (c == '\t')
                {
                    c = ' ';
                }

                if (c == '\n')
                {
                    // 下にはみ出したら抜ける
                    if (layout.BreakLine() == false)
                    {
                        break;
                    }
                }
                else if (_font.GetCharacterInfo(c, out ch) == true)
                {
                    // 行はみ出した
                    if (layout.TryPut(ref ch) == false)
                    {
                        // 自動改行でないなら抜ける。改行してみてはみ出したら抜ける
                        if (!autoLineBreak || (layout.BreakLine() == false))
                        {
                            break;
                        }
                    }

                    if (AddChar(
                            left + layout.x,
                            top - layout.y - ascent,
                            scale,
                            ref ch) == false)
                    {
                        break;
                    }
                    layout.Put(ref ch);
                }
            }
        }