Esempio n. 1
0
        public static Box CreateBoxHorizontal(string symbol, float minWidth)
        {
            minWidth += TEXConfiguration.main.DelimiterRecursiveOffset;
            var ch = TEXPreference.main.GetChar(symbol).GetMetric();

            var  ch2 = TEXPreference.main.GetChar(symbol);
            bool isAlreadyHorizontal = true;

            while (ch2 != null)
            {
                if (ch2.extensionExist && !ch2.extensionHorizontal)
                {
                    isAlreadyHorizontal = false;
                    break;
                }
                ch2 = ch2.nextLarger;
            }

            // Find first version of character that has at least minimum width.
            var totalWidth = isAlreadyHorizontal ? ch.bearing + ch.italic : ch.totalHeight;

            while (totalWidth < minWidth && ch.ch.nextLargerExist)
            {
                ch.Flush();
                ch         = ch.ch.nextLarger.GetMetric();
                totalWidth = isAlreadyHorizontal ? ch.bearing + ch.italic : ch.totalHeight;
            }

            if (totalWidth < minWidth && ch.ch.extensionExist)
            {
                var resultBox = HorizontalBox.Get();
                resultBox.ExtensionMode = true;
                // Construct box from extension character.
                var ext = ch.ch.GetExtentMetrics();
                if (isAlreadyHorizontal)
                {
                    if (ext[0] != null)
                    {
                        resultBox.Add(ext[0]);
                    }
                    if (ext[1] != null)
                    {
                        resultBox.Add(ext[1]);
                    }
                    if (ext[2] != null)
                    {
                        resultBox.Add(ext[2]);
                    }
                }
                else
                {
                    if (ext[2] != null)
                    {
                        resultBox.Add(RotatedCharBox.Get(ext[2]));
                    }
                    if (ext[1] != null)
                    {
                        resultBox.Add(RotatedCharBox.Get(ext[1]));
                    }
                    if (ext[0] != null)
                    {
                        resultBox.Add(RotatedCharBox.Get(ext[0]));
                    }
                }

                // Insert repeatable part multiple times until box is high enough.
                if (ext[3] != null)
                {
                    Box repeatBox = isAlreadyHorizontal ? (Box)ext[3] : RotatedCharBox.Get(ext[3]);
                    do
                    {
                        if (ext[0] != null && ext[2] != null)
                        {
                            resultBox.Add(1, repeatBox);
                            if (ext[1] != null)
                            {
                                resultBox.Add(resultBox.children.Count - 1, repeatBox);
                            }
                        }
                        else if (ext[2] != null)
                        {
                            resultBox.Add(0, repeatBox);
                        }
                        else
                        {
                            resultBox.Add(repeatBox);
                        }
                    }while (resultBox.width < minWidth);
                }
                return(resultBox);
            }
            else
            {
                // Just enough
                if (isAlreadyHorizontal)
                {
                    return(ch);
                }
                else
                {
                    return(RotatedCharBox.Get(ch.ch));
                }
            }
        }
Esempio n. 2
0
        public static Box CreateBoxHorizontal(string symbol, float minWidth, TexStyle style)
        {
            var charInfo = TEXPreference.main.GetCharMetric(symbol, style);

            var  charInfo2           = TEXPreference.main.GetChar(symbol);
            bool isAlreadyHorizontal = true;

            while (charInfo2 != null)
            {
                if (charInfo2.extensionExist && !charInfo2.extensionHorizontal)
                {
                    isAlreadyHorizontal = false;
                    break;
                }
                charInfo2 = charInfo2.nextLarger;
            }

            // Find first version of character that has at least minimum width.
            var totalWidth = isAlreadyHorizontal ? charInfo.bearing + charInfo.italic : charInfo.totalHeight;

            while (totalWidth < minWidth && charInfo.ch.nextLargerExist)
            {
                charInfo   = TEXPreference.main.GetCharMetric(charInfo.ch.nextLarger, style);
                totalWidth = isAlreadyHorizontal ? charInfo.bearing + charInfo.italic : charInfo.totalHeight;
            }

            if (totalWidth >= minWidth)
            {
                // Character of sufficient height was found.
                if (isAlreadyHorizontal)
                {
                    return(CharBox.Get(style, charInfo));
                }
                else
                {
                    return(RotatedCharBox.Get(style, charInfo));
                }
            }
            else if (charInfo.ch.extensionExist)
            {
                var resultBox = HorizontalBox.Get();
                resultBox.ExtensionMode = true;
                // Construct box from extension character.
                var extension = charInfo.ch.GetExtentMetrics(style);
                if (isAlreadyHorizontal)
                {
                    if (extension[0] != null)
                    {
                        resultBox.Add(CharBox.Get(style, extension[0]));
                    }
                    if (extension[1] != null)
                    {
                        resultBox.Add(CharBox.Get(style, extension[1]));
                    }
                    if (extension[2] != null)
                    {
                        resultBox.Add(CharBox.Get(style, extension[2]));
                    }
                }
                else
                {
                    if (extension[2] != null)
                    {
                        resultBox.Add(RotatedCharBox.Get(style, extension[2]));
                    }
                    if (extension[1] != null)
                    {
                        resultBox.Add(RotatedCharBox.Get(style, extension[1]));
                    }
                    if (extension[0] != null)
                    {
                        resultBox.Add(RotatedCharBox.Get(style, extension[0]));
                    }
                }

                // Insert repeatable part multiple times until box is high enough.
                if (extension[3] != null)
                {
                    Box repeatBox;
                    if (isAlreadyHorizontal)
                    {
                        repeatBox = CharBox.Get(style, extension[3]);
                    }
                    else
                    {
                        repeatBox = RotatedCharBox.Get(style, extension[3]);
                    }
                    do
                    {
                        if (extension[0] != null && extension[2] != null)
                        {
                            resultBox.Add(1, repeatBox);
                            if (extension[1] != null)
                            {
                                resultBox.Add(resultBox.children.Count - 1, repeatBox);
                            }
                        }
                        else if (extension[2] != null)
                        {
                            resultBox.Add(0, repeatBox);
                        }
                        else
                        {
                            resultBox.Add(repeatBox);
                        }
                    }while (resultBox.width < minWidth);
                }
                return(resultBox);
            }
            else
            {
                // No extensions available, so use tallest available version of character.
                if (isAlreadyHorizontal)
                {
                    return(CharBox.Get(style, charInfo));
                }
                else
                {
                    return(RotatedCharBox.Get(style, charInfo));
                }
            }
        }