示例#1
0
 public TexRenderer GetRenderer()
 {
     // For compactness:
     // Scale isn't saved, but stored in TexUtility.RenderSizeFactor (and normalized)
     // The actual scaling (param above) is just saved in here, not on each boxes.
     // Color isn't saved, but stored in TexUtility.RenderColor or as a box of AttrColorBox (for \color).
     // FontIndex & FontStyle isn't saved, but stored in TexUtility.RenderFont & TexUtility.Style
     try
     {
         var box = CreateBox();
         return(TexRenderer.Get(box as HorizontalBox ??
                                HorizontalBox.Get(box), AttachedMetaRenderer));
     }
     catch (Exception e)
     {
         throw e;
     }
 }
示例#2
0
        public TexRenderer GetRenderer(TexStyle style, float scale)
        {
            // For compactness:
            // Scale isn't saved, but stored in TexUtility.RenderSizeFactor (and normalized)
            // The actual scaling (param above) is just saved in here, not on each boxes.
            // Color isn't saved, but stored in TexUtility.RenderColor or as a box of AttrColorBox (for \color).
            // FontIndex & FontStyle isn't saved, but stored in TexUtility.RenderFont & TexUtility.RenderFontStyle
            try
            {
                TexUtility.RenderSizeFactor = 1;
                return(TexRenderer.Get(CreateBox(style), scale, AttachedMetaRenderer));
            }
#if UNITY_EDITOR
            catch (Exception e)
            {
                throw e;
            }
#else
            catch (Exception) {
            }
            return(null);
#endif
        }
示例#3
0
        // Branched wrapping algorithm for RTL support based above.
        private void HandlePerLineWrappingReversed(int i)
        {
            TexRenderer   row = m_formulas[i], newrow;
            HorizontalBox box = (HorizontalBox)row.Box;
            List <Box>    ch  = box.children;

            float x = row.PenaltyWidth, xPenalty = x, lastSpaceX = 0;
            int   lastSpaceIdx = -1, last = ch.Count - 1;

            //Begin Per-character pooling
            for (int j = ch.Count; j-- > 0;)
            {
                var child = ch[j];
                //White line? make a mark
                if (child is StrutBox && ((StrutBox)child).policy == StrutPolicy.BlankSpace)
                {
                    lastSpaceIdx = j;                   //last space, index
                    lastSpaceX   = x;                   //last space, x position
                    _spaceIdxs.Add(lastSpaceIdx);       //record that space
                    child.width = _realBlankSpaceWidth; // All spaces must have this width (they may modified after WordWarpJusified).
                }
                x += ch[j].width;
                //Total length not yet to break our rect limit? continue
                if (x * scale <= rectArea.width)
                {
                    if (_doJustify && (0 == j))
                    {
                        box.Recalculate();
                    }
                    continue;
                }
                //Now j is maximum limit character length. Now move any
                //character before that to the new previous line

                //Did we use word wrap? Track the last space index
                if (_useWordWrap && lastSpaceIdx >= 0)
                {
                    j = lastSpaceIdx;
                    x = lastSpaceX;
                    //Justify too? then expand our spaces width
                    if (_doJustify && _spaceIdxs.Count > 1)
                    {
                        float normalizedWidth = rectArea.width / scale;
                        float extraWidth      = (normalizedWidth - x) / (_spaceIdxs.Count - 1);
                        for (int k = 0; k < _spaceIdxs.Count; k++)
                        {
                            ch[_spaceIdxs[k]].width += extraWidth;
                        }
                        x = normalizedWidth;
                    }
                }
                else
                {
                    x -= ch[j].width;
                }
                if (j == last && (!_useWordWrap || lastSpaceIdx != j))
                {
                    // infinite loop prevention
                    x += ch[j].width;
                    continue;
                }
                var doOmitSpace = (_useWordWrap && lastSpaceIdx >= 0);
                m_formulas.Insert(i, newrow = TexRenderer.Get(HorizontalBox.Get(ch.GetRangePool(j + 1, last - j)),
                                                              row.metaRules, row.partOfPreviousLine)); //Add to previous line,
                if (doOmitSpace)
                {
                    j--; box.width -= ch[lastSpaceIdx].width; ch[lastSpaceIdx].Flush();
                }
                ch.RemoveRange(j + 1, last - j);
                //Update our measurements, remember now m_formulas[i] is different with box
                row.partOfPreviousLine = doOmitSpace ? 2 : 1;
                box.width -= newrow.Box.width = x - xPenalty;
                size.x     = Mathf.Max(size.x, x);
                size.y    += newrow.CompleteHeight * scale;
                break;
            }
        }
示例#4
0
        // Branched wrapping algorithm for RTL support based above.
        void HandlePerLineWrappingReversed(Box box, int i)
        {
            float x = formulas[i].PenaltyWidth, xPenalty = x, xOri = 0, y = 0, lastSpaceX = 0;
            int   lastSpaceIdx  = -1;
            bool  requestToSkip = false;

            //Begin Per-character pooling
            for (int j = box.children.Count; j-- > 0;)
            {
                var child = box.children[j];
                //White line? make a mark
                if (child is StrutBox && ((StrutBox)child).policy == StrutPolicy.BlankSpace)
                {
                    lastSpaceIdx = j;                   //last space, index
                    lastSpaceX   = x;                   //last space, x position
                    _spaceIdxs.Add(lastSpaceIdx);       //record that space
                    child.width = _realBlankSpaceWidth; // All spaces must have this width (they may modified after WordWarpJusified).
                }
                x   += box.children[j].width;
                xOri = x - xPenalty;
                //Total length not yet to break our rect limit? continue
                if (x * scale <= rectArea.width)
                {
                    if (_doJustify && (0 == j))
                    {
                        ((HorizontalBox)box).Recalculate();
                    }
                    continue;
                }
                //Now j is maximum limit character length. Now move any
                //character before that to the new previous line

                //Did we use word wrap? Track the last space index
                if (_useWordWrap && lastSpaceIdx >= 0 && lastSpaceIdx < box.children.Count - 1)
                {
                    //Already ommited since it is exluded
                    j             = lastSpaceIdx;
                    x             = lastSpaceX;
                    xOri          = lastSpaceX - xPenalty + box.children[lastSpaceIdx].width;
                    requestToSkip = true;
                    //Justify too? then expand our spaces width
                    if (_doJustify && _spaceIdxs.Count > 1)
                    {
                        float normalizedWidth = rectArea.width / scale;
                        float extraWidth      = (normalizedWidth - x) / (float)(_spaceIdxs.Count - 1);
                        for (int k = 0; k < _spaceIdxs.Count; k++)
                        {
                            box.children[_spaceIdxs[k]].width += extraWidth;
                        }
                        x = normalizedWidth;
                    }
                }
                else if (box.children[j] is StrutBox && ((StrutBox)box.children[j]).policy == StrutPolicy.BlankSpace)
                {
                    x            -= box.children[j].width;
                    requestToSkip = true;
                }
                else
                {
                    x   -= box.children[j].width;
                    xOri = x - xPenalty;
                }
                if (j > box.children.Count - 2)
                {
                    x   += box.children[j].width;
                    xOri = x - xPenalty;
                    continue;
                }
                int oriPartMark = m_formulas[i].partOfPreviousLine;
                m_formulas[i].partOfPreviousLine = (_useWordWrap && lastSpaceIdx >= 0) ? 2 : 1;
                if (requestToSkip)
                {
                    j--; // Skip the unneeded space char
                }
                m_formulas.Insert(i, TexRenderer.Get(HorizontalBox.Get(
                                                         box.children.GetRangePool(j + 1, box.children.Count - j - 1)), originalScale, m_formulas[i].metaRules)); //Add to previous line,
                box.children.RemoveRange(j + 1, box.children.Count - j - 1);
                //Update our measurements, remember now m_formulas[i] is different with box
                if (oriPartMark > 0)
                {
                    m_formulas[i].partOfPreviousLine = oriPartMark;
                }
                box.width -= xOri;
                y          = m_formulas[i].Box.totalHeight;
                if (oriPartMark > 0)
                {
                    y += m_formulas[i].PenaltyParagraph;
                }
                if (requestToSkip)
                {
                    formulas[i].Box.shift -= m_formulas[i].Box.children[0].width;
                }
                formulas[i].Box.width = x - xPenalty;
                size.x  = Mathf.Max(size.x, x);
                size.y += (spaceSize + m_formulas[i].PenaltySpacing + y) * scale;
                break;
            }
        }