예제 #1
0
 internal int GetHeight(Win32DCSafeHandle hdc, FontCache fontCache)
 {
     if (!m_calculatedHeight)
     {
         m_calculatedHeight = true;
         for (int i = 0; i < m_logicalRuns.Count; i++)
         {
             TextRun textRun = m_logicalRuns[i];
             int     ascent  = textRun.GetAscent(hdc, fontCache);
             if (ascent > m_ascent)
             {
                 m_ascent = ascent;
             }
             int descent = textRun.GetDescent(hdc, fontCache);
             if (descent > m_descent)
             {
                 m_descent = descent;
             }
         }
         if (m_prefix != null)
         {
             for (int j = 0; j < m_prefix.Count; j++)
             {
                 TextRun textRun2 = m_prefix[j];
                 int     ascent2  = textRun2.GetAscent(hdc, fontCache);
                 if (ascent2 > m_ascent)
                 {
                     m_ascent = ascent2;
                 }
                 int descent2 = textRun2.GetDescent(hdc, fontCache);
                 if (descent2 > m_descent)
                 {
                     m_descent = descent2;
                 }
             }
         }
     }
     return(m_ascent + m_descent);
 }
예제 #2
0
        private void CalculateDimensions(Win32DCSafeHandle hdc, FontCache fontCache, bool useVisualRunsIfAvailable)
        {
            if (m_calculatedDimensions)
            {
                return;
            }
            bool           flag = useVisualRunsIfAvailable && m_visualRuns != null;
            List <TextRun> list = flag ? m_visualRuns : m_logicalRuns;

            m_width       = 0;
            m_prefixWidth = 0;
            int count = list.Count;
            int num   = 0;

            for (int i = 0; i < count; i++)
            {
                TextRun textRun = list[i];
                int     width   = textRun.GetWidth(hdc, fontCache);
                m_width += width;
                if (!flag)
                {
                    num = Math.Max(textRun.GetWidth(hdc, fontCache, isAtLineEnd: true) - width, num);
                }
                else if (i == count - 1)
                {
                    num = textRun.GetWidth(hdc, fontCache, isAtLineEnd: true) - width;
                }
                if (!m_calculatedHeight)
                {
                    int ascent = textRun.GetAscent(hdc, fontCache);
                    if (ascent > m_ascent)
                    {
                        m_ascent = ascent;
                    }
                    int descent = textRun.GetDescent(hdc, fontCache);
                    if (descent > m_descent)
                    {
                        m_descent = descent;
                    }
                }
            }
            m_width += num;
            if (m_prefix != null)
            {
                for (int j = 0; j < m_prefix.Count; j++)
                {
                    TextRun textRun2 = m_prefix[j];
                    if (!m_calculatedHeight)
                    {
                        int ascent2 = textRun2.GetAscent(hdc, fontCache);
                        if (ascent2 > m_ascent)
                        {
                            m_ascent = ascent2;
                        }
                        int descent2 = textRun2.GetDescent(hdc, fontCache);
                        if (descent2 > m_descent)
                        {
                            m_descent = descent2;
                        }
                    }
                    m_prefixWidth += textRun2.GetWidth(hdc, fontCache);
                }
            }
            m_calculatedDimensions = true;
            m_calculatedHeight     = true;
        }