Esempio n. 1
0
        public static void ExtDrawTextRun(TextRun run, Win32DCSafeHandle hdc, FontCache fontCache, int x, int baselineY, Underline underline)
        {
            uint crColor = 0u;

            try
            {
                uint colorInt = run.ColorInt;
                if (underline != null)
                {
                    underline.Draw(hdc, (int)((double)run.UnderlineHeight * 0.085), colorInt);
                }
                crColor = Win32.SetTextColor(hdc, colorInt);
                CachedFont cachedFont = run.GetCachedFont(hdc, fontCache);
                fontCache.SelectFontObject(hdc, cachedFont.Hfont);
                int[] lpDx      = null;
                uint  fuOptions = 0u;
                if (run.ScriptAnalysis.fRTL == 1)
                {
                    fuOptions = 128u;
                }
                if (!Win32.ExtTextOut(hdc, x, baselineY, fuOptions, IntPtr.Zero, run.Text, (uint)run.Text.Length, lpDx))
                {
                    Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                }
            }
            finally
            {
                crColor = Win32.SetTextColor(hdc, crColor);
            }
        }
Esempio n. 2
0
        public static void DrawTextRun(TextRun run, Win32DCSafeHandle hdc, FontCache fontCache, int x, int baselineY, Underline underline)
        {
            uint crColor = 0u;

            try
            {
                uint colorInt = run.ColorInt;
                if (underline != null)
                {
                    underline.Draw(hdc, (int)((double)run.UnderlineHeight * 0.085), colorInt);
                }
                crColor = Win32.SetTextColor(hdc, colorInt);
                GlyphData      glyphData            = run.GetGlyphData(hdc, fontCache);
                GlyphShapeData glyphScriptShapeData = glyphData.GlyphScriptShapeData;
                CachedFont     cachedFont           = run.GetCachedFont(hdc, fontCache);
                fontCache.SelectFontObject(hdc, cachedFont.Hfont);
                int num = Win32.ScriptTextOut(hdc, ref cachedFont.ScriptCache, x, baselineY, 4u, IntPtr.Zero, ref run.SCRIPT_ANALYSIS, IntPtr.Zero, 0, glyphScriptShapeData.Glyphs, glyphScriptShapeData.GlyphCount, glyphData.Advances, (int[])null, glyphData.GOffsets);
                if (Win32.Failed(num))
                {
                    Marshal.ThrowExceptionForHR(num);
                }
            }
            finally
            {
                crColor = Win32.SetTextColor(hdc, crColor);
            }
        }
Esempio n. 3
0
        private CachedFont CreateFont(ITextRunProps textRun, string key, byte charset, bool verticalFont, string fontFamily, float fontSize)
        {
            CachedFont cachedFont = new CachedFont();

            this.m_fontDict.Add(key, cachedFont);
            bool bold   = textRun.Bold;
            bool italic = textRun.Italic;

            RPLFormat.TextDecorations textDecoration = textRun.TextDecoration;
            bool lineThrough = textDecoration == RPLFormat.TextDecorations.LineThrough;

            cachedFont.Font = FontCache.CreateGdiPlusFont(fontFamily, textRun.FontSize, ref bold, ref italic, lineThrough, false);
            int num = 0;

            if (this.UseEmSquare)
            {
                int emHeight = cachedFont.Font.FontFamily.GetEmHeight(cachedFont.Font.Style);
                cachedFont.ScaleFactor = (float)emHeight / fontSize;
                num = emHeight;
            }
            else
            {
                num = (int)(fontSize + 0.5);
            }
            cachedFont.Hfont = this.CreateGdiFont(this.m_writingMode, num, bold, italic, lineThrough, charset, verticalFont, cachedFont.Font.FontFamily.Name);
            return(cachedFont);
        }
Esempio n. 4
0
        private void TextScriptPlace(Win32DCSafeHandle hdc, bool fontSelected, FontCache fontCache)
        {
            int            num = 0;
            GlyphShapeData glyphScriptShapeData = this.m_cachedGlyphData.GlyphScriptShapeData;

            if (fontSelected)
            {
                num = Win32.ScriptPlace(hdc, ref this.m_cachedFont.ScriptCache, glyphScriptShapeData.Glyphs, glyphScriptShapeData.GlyphCount, glyphScriptShapeData.VisAttrs, ref this.SCRIPT_ANALYSIS, this.m_cachedGlyphData.RawAdvances, this.m_cachedGlyphData.RawGOffsets, ref this.m_cachedGlyphData.ABC);
            }
            else
            {
                num = Win32.ScriptPlace(IntPtr.Zero, ref this.m_cachedFont.ScriptCache, glyphScriptShapeData.Glyphs, glyphScriptShapeData.GlyphCount, glyphScriptShapeData.VisAttrs, ref this.SCRIPT_ANALYSIS, this.m_cachedGlyphData.RawAdvances, this.m_cachedGlyphData.RawGOffsets, ref this.m_cachedGlyphData.ABC);
                if (num == -2147483638)
                {
                    fontCache.SelectFontObject(hdc, this.m_cachedFont.Hfont);
                    num = Win32.ScriptPlace(hdc, ref this.m_cachedFont.ScriptCache, glyphScriptShapeData.Glyphs, glyphScriptShapeData.GlyphCount, glyphScriptShapeData.VisAttrs, ref this.SCRIPT_ANALYSIS, this.m_cachedGlyphData.RawAdvances, this.m_cachedGlyphData.RawGOffsets, ref this.m_cachedGlyphData.ABC);
                }
            }
            if (Win32.Failed(num))
            {
                Marshal.ThrowExceptionForHR(num);
            }
            if (this.m_cachedGlyphData.ABC.Width > 0 && this.m_text.Length == 1 && TextBox.IsWhitespaceControlChar(this.m_text[0]))
            {
                this.m_cachedGlyphData.ABC.SetToZeroWidth();
            }
        }
 public int GetLeading(Win32DCSafeHandle hdc, FontCache fontCache)
 {
     if (!this.m_initialized)
     {
         this.Initialize(hdc, fontCache);
     }
     return(this.m_textMetric.tminternalLeading);
 }
 public int GetDescent(Win32DCSafeHandle hdc, FontCache fontCache)
 {
     if (!this.m_initialized)
     {
         this.Initialize(hdc, fontCache);
     }
     return(this.m_textMetric.tmDescent);
 }
Esempio n. 7
0
 public void Dispose()
 {
     if (this.m_fontCache != null)
     {
         this.m_fontCache.Dispose();
         this.m_fontCache = null;
     }
     GC.SuppressFinalize(this);
 }
Esempio n. 8
0
 private void LoadGlyphData(Win32DCSafeHandle hdc, FontCache fontCache)
 {
     if (!this.m_clone && this.m_cachedGlyphData.NeedGlyphPlaceData)
     {
         this.m_cachedGlyphData.NeedGlyphPlaceData = false;
         this.m_cachedGlyphData.ScaleFactor        = this.m_cachedFont.ScaleFactor;
         this.TextScriptPlace(hdc, false, fontCache);
     }
 }
Esempio n. 9
0
 public int GetPrefixWidth(Win32DCSafeHandle hdc, FontCache fontCache)
 {
     if (this.m_prefix == null)
     {
         return(0);
     }
     this.CalculateDimensions(hdc, fontCache, true);
     return(this.m_prefixWidth);
 }
Esempio n. 10
0
 public int GetWidth(Win32DCSafeHandle hdc, FontCache fontCache, bool isAtLineEnd)
 {
     if (this.m_cachedGlyphData == null)
     {
         this.ShapeAndPlace(hdc, fontCache);
     }
     else
     {
         this.LoadGlyphData(hdc, fontCache);
     }
     return(this.m_cachedGlyphData.GetTotalWidth(isAtLineEnd));
 }
Esempio n. 11
0
 public GlyphData GetGlyphData(Win32DCSafeHandle hdc, FontCache fontCache)
 {
     if (this.m_cachedGlyphData == null)
     {
         this.ShapeAndPlace(hdc, fontCache);
     }
     else
     {
         this.LoadGlyphData(hdc, fontCache);
     }
     return(this.m_cachedGlyphData);
 }
Esempio n. 12
0
 private void Initialize(Win32DCSafeHandle hdc, FontCache fontCache)
 {
     fontCache.SelectFontObject(hdc, this.m_hfont);
     Win32.GetTextMetrics(hdc, out this.m_textMetric);
     if (this.ScaleFactor != 1.0)
     {
         this.m_textMetric.tmHeight          = this.Scale(this.m_textMetric.tmHeight);
         this.m_textMetric.tmAscent          = this.Scale(this.m_textMetric.tmAscent);
         this.m_textMetric.tmDescent         = this.Scale(this.m_textMetric.tmDescent);
         this.m_textMetric.tminternalLeading = this.Scale(this.m_textMetric.tminternalLeading);
     }
     this.m_initialized = true;
 }
Esempio n. 13
0
        public static List <Paragraph> Flow(TextBox textBox, Graphics g, FontCache fontCache, FlowContext flowContext, bool keepLines, out float height)
        {
            List <Paragraph>  list = null;
            float             dpiX = g.DpiX;
            Win32DCSafeHandle win32DCSafeHandle = new Win32DCSafeHandle(g.GetHdc(), false);

            try
            {
                return(LineBreaker.Flow(textBox, win32DCSafeHandle, dpiX, fontCache, flowContext, keepLines, out height));
            }
            finally
            {
                fontCache.ResetGraphics();
                if (!win32DCSafeHandle.IsInvalid)
                {
                    g.ReleaseHdc();
                }
            }
        }
Esempio n. 14
0
        public int[] GetLogicalWidths(Win32DCSafeHandle hdc, FontCache fontCache)
        {
            GlyphData glyphData = this.GetGlyphData(hdc, fontCache);

            int[] array = new int[this.m_text.Length];
            int   num   = Win32.ScriptGetLogicalWidths(ref this.SCRIPT_ANALYSIS, this.m_text.Length, glyphData.GlyphScriptShapeData.GlyphCount, glyphData.ScaledAdvances, glyphData.GlyphScriptShapeData.Clusters, glyphData.GlyphScriptShapeData.VisAttrs, array);

            if (Win32.Failed(num))
            {
                Marshal.ThrowExceptionForHR(num);
            }
            if (glyphData.Scaled)
            {
                for (int i = 0; i < array.Length; i++)
                {
                    array[i] = glyphData.Scale(array[i]);
                }
            }
            return(array);
        }
Esempio n. 15
0
 public int GetHeight(Win32DCSafeHandle hdc, FontCache fontCache)
 {
     if (!this.m_calculatedHeight)
     {
         this.m_calculatedHeight = true;
         for (int i = 0; i < this.m_logicalRuns.Count; i++)
         {
             TextRun textRun = this.m_logicalRuns[i];
             int     ascent  = textRun.GetAscent(hdc, fontCache);
             if (ascent > this.m_ascent)
             {
                 this.m_ascent = ascent;
             }
             int descent = textRun.GetDescent(hdc, fontCache);
             if (descent > this.m_descent)
             {
                 this.m_descent = descent;
             }
         }
         if (this.m_prefix != null)
         {
             for (int j = 0; j < this.m_prefix.Count; j++)
             {
                 TextRun textRun2 = this.m_prefix[j];
                 int     ascent2  = textRun2.GetAscent(hdc, fontCache);
                 if (ascent2 > this.m_ascent)
                 {
                     this.m_ascent = ascent2;
                 }
                 int descent2 = textRun2.GetDescent(hdc, fontCache);
                 if (descent2 > this.m_descent)
                 {
                     this.m_descent = descent2;
                 }
             }
         }
     }
     return(this.m_ascent + this.m_descent);
 }
Esempio n. 16
0
        public static void DrawClippedTextRun(TextRun run, Win32DCSafeHandle hdc, FontCache fontCache, int x, int baselineY, uint fontColorOverride, Rectangle clipRect, Underline underline)
        {
            uint   crColor = 0u;
            IntPtr intPtr  = IntPtr.Zero;

            try
            {
                if (underline != null)
                {
                    underline.Draw(hdc, (int)((double)run.UnderlineHeight * 0.085), fontColorOverride);
                }
                RECT rECT = default(RECT);
                rECT.left   = clipRect.Left;
                rECT.right  = clipRect.Right;
                rECT.top    = clipRect.Top;
                rECT.bottom = clipRect.Bottom;
                crColor     = Win32.SetTextColor(hdc, fontColorOverride);
                GlyphData      glyphData            = run.GetGlyphData(hdc, fontCache);
                GlyphShapeData glyphScriptShapeData = glyphData.GlyphScriptShapeData;
                CachedFont     cachedFont           = run.GetCachedFont(hdc, fontCache);
                fontCache.SelectFontObject(hdc, cachedFont.Hfont);
                intPtr = Marshal.AllocHGlobal(Marshal.SizeOf(rECT));
                Marshal.StructureToPtr(rECT, intPtr, false);
                int num = Win32.ScriptTextOut(hdc, ref cachedFont.ScriptCache, x, baselineY, 4u, intPtr, ref run.SCRIPT_ANALYSIS, IntPtr.Zero, 0, glyphScriptShapeData.Glyphs, glyphScriptShapeData.GlyphCount, glyphData.Advances, (int[])null, glyphData.GOffsets);
                if (Win32.Failed(num))
                {
                    Marshal.ThrowExceptionForHR(num);
                }
            }
            finally
            {
                if (intPtr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(intPtr);
                }
                crColor = Win32.SetTextColor(hdc, crColor);
            }
        }
Esempio n. 17
0
        public Underline(TextRun run, Win32DCSafeHandle hdc, FontCache fontCache, Rectangle layoutRectangle, int x, int baselineY, RPLFormat.WritingModes writingMode)
        {
            int width = run.GetWidth(hdc, fontCache);
            int num   = (int)((double)(int)((double)run.UnderlineHeight * 0.085) * 1.5);

            switch (writingMode)
            {
            case RPLFormat.WritingModes.Horizontal:
                this.m_startPoint = new Point(layoutRectangle.X + x, layoutRectangle.Y + baselineY + num);
                this.m_endPoint   = new Point(Math.Min(this.m_startPoint.X + width, layoutRectangle.Right), this.m_startPoint.Y);
                break;

            case RPLFormat.WritingModes.Vertical:
                this.m_startPoint = new Point(layoutRectangle.Right - baselineY - num - 1, layoutRectangle.Y + x);
                this.m_endPoint   = new Point(this.m_startPoint.X, Math.Min(this.m_startPoint.Y + width, layoutRectangle.Bottom));
                break;

            case RPLFormat.WritingModes.Rotate270:
                this.m_startPoint = new Point(layoutRectangle.X + baselineY + num, layoutRectangle.Bottom - x);
                this.m_endPoint   = new Point(this.m_startPoint.X, Math.Max(this.m_startPoint.Y - width, layoutRectangle.Top));
                break;
            }
        }
Esempio n. 18
0
        private static int FindFoldTextPosition_CharacterTrim(TextRun run, Win32DCSafeHandle hdc, FontCache fontCache, float maxWidth)
        {
            string text = run.Text;

            int[] logicalWidths = run.GetLogicalWidths(hdc, fontCache);
            int   i             = 0;

            for (int num = 0; i < text.Length && (float)(num + logicalWidths[i]) <= maxWidth; i++)
            {
                num += logicalWidths[i];
            }
            return(i);
        }
Esempio n. 19
0
        private static bool GetLine(Paragraph paragraph, TextLine line, Win32DCSafeHandle hdc, FontCache fontCache, FlowContext flowContext, float left, float right, float height, Stack <int> lineRunsIndex, Stack <int> lineRunsCharIndex, int lineIndents)
        {
            float num  = right - left;
            float num2 = left;
            bool  flag = false;
            int   num3 = 0;

            do
            {
                lineRunsIndex.Push(flowContext.Context.TextRunIndex);
                lineRunsCharIndex.Push(flowContext.Context.TextRunCharacterIndex);
                TextRun subRunForLine = paragraph.GetSubRunForLine(flowContext.Context, ref flag);
                if (subRunForLine == null)
                {
                    break;
                }
                line.LogicalRuns.Add(subRunForLine);
                int width = subRunForLine.GetWidth(hdc, fontCache);
                num3  = Math.Max(subRunForLine.GetWidth(hdc, fontCache, true) - width, num3);
                num2 += (float)width;
                if (num2 + (float)num3 > right)
                {
                    bool flag2 = flowContext.WordTrim;
                    if (!flowContext.LineLimit && flag2)
                    {
                        if ((float)line.GetHeight(hdc, fontCache) >= height)
                        {
                            flag2 = false;
                        }
                        line.ResetHeight();
                    }
                    if (!subRunForLine.IsPlaceholderTextRun)
                    {
                        LineBreaker.FoldLine(paragraph, line, hdc, fontCache, flowContext, flag2, lineRunsIndex, lineRunsCharIndex, num - (float)num3, lineIndents);
                        break;
                    }
                    lineRunsIndex.Push(flowContext.Context.TextRunIndex);
                    lineRunsCharIndex.Push(flowContext.Context.TextRunCharacterIndex);
                    bool    flag3          = true;
                    TextRun subRunForLine2 = paragraph.GetSubRunForLine(flowContext.Context, ref flag);
                    if (subRunForLine2 != null)
                    {
                        flag3 = (subRunForLine.TextRunProperties.IndexInParagraph < subRunForLine2.TextRunProperties.IndexInParagraph);
                    }
                    flowContext.Context.TextRunIndex          = lineRunsIndex.Pop();
                    flowContext.Context.TextRunCharacterIndex = lineRunsCharIndex.Pop();
                    if (flag3)
                    {
                        LineBreaker.FoldLine(paragraph, line, hdc, fontCache, flowContext, flag2, lineRunsIndex, lineRunsCharIndex, num - (float)num3, lineIndents);
                        break;
                    }
                }
            }while (!flag);
            if (line.LogicalRuns.Count == 0)
            {
                return(false);
            }
            return(true);
        }
Esempio n. 20
0
        public static float MeasureFullHeight(TextBox textBox, Graphics g, FontCache fontCache, FlowContext flowContext, out float contentHeight)
        {
            if (flowContext.Width <= 0.0)
            {
                contentHeight = 0f;
                return(0f);
            }
            FlowContext flowContext2 = flowContext.Clone();

            flowContext2.Reset();
            flowContext2.Height = 3.40282347E+38f;
            float num = 0f;

            if (textBox.VerticalText)
            {
                flowContext2.LineLimit = false;
                float num2 = 0f;
                float val  = 0f;
                float num3 = 0f;
                float num4 = flowContext.Height;
                float num5 = 0f;
                if (flowContext.Height == 3.4028234663852886E+38)
                {
                    num4 = 0f;
                }
                num3 = (contentHeight = LineBreaker.FlowVertical(textBox, g, fontCache, flowContext2, out num2, out val));
                num  = num2;
                num5 = num2;
                bool  flag = flowContext2.CharTrimmedRunWidth > 0;
                float num6 = 0f;
                while (num3 < flowContext.Width && num2 > num4)
                {
                    flowContext2.Reset();
                    flowContext2.Height = Math.Max(val, num4);
                    flowContext2.Width  = 3.40282347E+38f;
                    num3 = LineBreaker.FlowVertical(textBox, g, fontCache, flowContext2, out num2, out val);
                    if (num3 < flowContext.Width)
                    {
                        num6 = num3 - contentHeight;
                        if (num3 <= contentHeight || num6 <= 0.10000000149011612)
                        {
                            if (flag)
                            {
                                contentHeight = num3;
                                num           = flowContext2.Height;
                                break;
                            }
                            if (flowContext2.CharTrimmedRunWidth <= 0)
                            {
                                break;
                            }
                        }
                        contentHeight = num3;
                        num           = flowContext2.Height;
                        num5          = num2;
                    }
                    else
                    {
                        num6 = num - flowContext2.Height;
                        if (!(num6 > 0.10000000149011612))
                        {
                            break;
                        }
                        val           = (float)(flowContext2.Height + (num - flowContext2.Height) / 2.0);
                        contentHeight = num3;
                        num2          = num5;
                    }
                    flag = (flowContext2.CharTrimmedRunWidth > 0);
                }
            }
            else
            {
                LineBreaker.Flow(textBox, g, fontCache, flowContext2, false, out contentHeight);
                num = contentHeight;
            }
            return(num);
        }
Esempio n. 21
0
        public static List <Paragraph> Flow(TextBox textBox, Graphics g, FontCache fontCache, FlowContext flowContext, bool keepLines)
        {
            float num = default(float);

            return(LineBreaker.Flow(textBox, g, fontCache, flowContext, keepLines, out num));
        }
Esempio n. 22
0
        private static void FoldLine(Paragraph paragraph, TextLine line, Win32DCSafeHandle hdc, FontCache fontCache, FlowContext flowContext, bool wordTrim, Stack <int> lineRunsIndex, Stack <int> lineRunsCharIndex, float maxWidth, int lineIndents)
        {
            int   count = line.LogicalRuns.Count;
            float num   = 0f;

            for (int i = 0; i < count; i++)
            {
                num += (float)line.LogicalRuns[i].GetWidth(hdc, fontCache);
            }
            int  num2 = -1;
            bool flag = false;

            for (int num3 = count - 1; num3 >= 0; num3--)
            {
                TextRun textRun = line.LogicalRuns[num3];
                num -= (float)textRun.GetWidth(hdc, fontCache);
                SCRIPT_LOGATTR?nextCharLogAttr = null;
                if (num3 != count - 1)
                {
                    TextRun textRun2 = line.LogicalRuns[num3 + 1];
                    if (textRun2.CharacterCount > 0)
                    {
                        nextCharLogAttr = textRun2.ScriptLogAttr[0];
                    }
                }
                if (!textRun.IsPlaceholderTextRun)
                {
                    flag = true;
                    int num4 = 0;
                    num4 = ((!wordTrim) ? LineBreaker.FindFoldTextPosition_CharacterTrim(textRun, hdc, fontCache, maxWidth - num) : LineBreaker.FindFoldTextPosition_TextRunTrim(textRun, hdc, fontCache, maxWidth - num, nextCharLogAttr));
                    if (num4 > 0)
                    {
                        LineBreaker.FoldLineAt(line, num3, num4, flowContext.Context, lineRunsIndex, lineRunsCharIndex);
                        return;
                    }
                }
                else if (num2 > 0 && textRun.TextRunProperties.IndexInParagraph != num2)
                {
                    flag = true;
                }
                num2 = textRun.TextRunProperties.IndexInParagraph;
            }
            if (line.LogicalRuns.Count > 1)
            {
                if (flag)
                {
                    int num5;
                    for (num5 = line.LogicalRuns.Count - 1; num5 > 0; num5--)
                    {
                        flowContext.Context.TextRunIndex          = lineRunsIndex.Pop();
                        flowContext.Context.TextRunCharacterIndex = lineRunsCharIndex.Pop();
                        TextRun textRun3 = line.LogicalRuns[num5];
                        if (!textRun3.IsPlaceholderTextRun)
                        {
                            break;
                        }
                        if (textRun3.CharacterIndexInOriginal == 0)
                        {
                            break;
                        }
                    }
                    line.LogicalRuns.RemoveRange(num5, line.LogicalRuns.Count - num5);
                }
            }
            else if (flag)
            {
                int num6 = 1;
                if (maxWidth > 0.0)
                {
                    flowContext.ForcedCharTrim = true;
                    if (flowContext.VerticalCanGrow)
                    {
                        int num7 = default(int);
                        num6 = LineBreaker.FindWidthToBreakPosition(line.LogicalRuns[0], hdc, fontCache, maxWidth, out num7);
                        flowContext.CharTrimmedRunWidth = Math.Max(flowContext.CharTrimmedRunWidth, num7 + lineIndents);
                    }
                    else
                    {
                        num6 = LineBreaker.FindFoldTextPosition_CharacterTrim(line.LogicalRuns[0], hdc, fontCache, maxWidth);
                    }
                    if (num6 == 0)
                    {
                        num6 = 1;
                    }
                }
                else if (line.FirstLine && paragraph.ParagraphProps.HangingIndent > 0.0)
                {
                    num6 = 0;
                    if (flowContext.Updatable)
                    {
                        paragraph.Updated = true;
                    }
                }
                LineBreaker.FoldLineAt(line, 0, num6, flowContext.Context, lineRunsIndex, lineRunsCharIndex);
            }
        }
Esempio n. 23
0
        private static void RenderHighlightedTextRun(TextBox textBox, Paragraph paragraph, TextRun run, TextRun prevRun, Win32DCSafeHandle hdc, Graphics g, FontCache fontCache, float dpiX, int x, int offsetY, int baselineY, int lineHeight, Rectangle layoutRectangle, int runWidth, int prevRunWidth, int prevRunX, bool lastRunInLine, bool lastLineInParagraph)
        {
            uint?     nullable  = null;
            Rectangle?nullable2 = null;
            bool      flag      = false;
            Color     color     = run.HighlightColor;
            int       num;
            int       num2;
            bool      flag2;

            if (!color.IsEmpty)
            {
                num  = ((run.HighlightStart >= 0) ? run.HighlightStart : 0);
                num2 = ((run.HighlightEnd >= 0) ? run.HighlightEnd : runWidth);
                if (lastRunInLine)
                {
                    flag2 = (run.ScriptAnalysis.fLayoutRTL == 1);
                    if (lastLineInParagraph && runWidth != 0)
                    {
                        if (num != num2)
                        {
                            if (flag2 && run.HighlightStart < 0)
                            {
                                goto IL_0094;
                            }
                            if (!flag2 && run.HighlightEnd < 0)
                            {
                                goto IL_0094;
                            }
                        }
                    }
                    else if (runWidth == 0)
                    {
                        if (flag2)
                        {
                            num -= 5;
                        }
                        else
                        {
                            num2 += 5;
                        }
                    }
                }
                goto IL_0102;
            }
            goto IL_024e;
IL_024e:
            if (runWidth > 0)
            {
                textBox.TextBoxProps.DrawTextRun(run, paragraph, hdc, dpiX, fontCache, x, offsetY, baselineY, lineHeight, layoutRectangle);
                if (nullable.HasValue)
                {
                    textBox.TextBoxProps.DrawClippedTextRun(run, paragraph, hdc, dpiX, fontCache, x, offsetY, baselineY, lineHeight, layoutRectangle, nullable.Value, nullable2.Value);
                }
            }
            if (flag)
            {
                Rectangle empty = Rectangle.Empty;
                empty = ((!textBox.HorizontalText) ? new Rectangle(layoutRectangle.Right - offsetY, layoutRectangle.Y + x, lineHeight, prevRunWidth) : new Rectangle(layoutRectangle.X + x, layoutRectangle.Y + offsetY - lineHeight, prevRunWidth, lineHeight));
                Color color2 = prevRun.TextRunProperties.Color;
                if (run.AllowColorInversion && TextBox.NeedsColorInversion(color, color2))
                {
                    color2   = TextBox.InvertColor(color2);
                    nullable = (uint)(color2.B << 16 | color2.G << 8 | color2.R);
                }
                else
                {
                    nullable = prevRun.ColorInt;
                }
                textBox.TextBoxProps.DrawClippedTextRun(prevRun, paragraph, hdc, dpiX, fontCache, prevRunX, offsetY, baselineY, lineHeight, layoutRectangle, nullable.Value, empty);
            }
            return;

IL_0094:
            if (flag2)
            {
                num -= 5;
                int abcA = run.GetGlyphData(hdc, fontCache).ABC.abcA;
                if (abcA < 0)
                {
                    num += abcA;
                }
            }
            else
            {
                num2 += 5;
                int abcC = run.GetGlyphData(hdc, fontCache).ABC.abcC;
                if (abcC < 0)
                {
                    num2 -= abcC;
                }
            }
            goto IL_0102;
IL_0102:
            if (num != num2)
            {
                if (num == 0 && prevRun != null && (prevRun.GetGlyphData(hdc, fontCache).ABC.abcC <= 0 || run.GetGlyphData(hdc, fontCache).ABC.abcA < 0))
                {
                    flag = true;
                }
                if (run.AllowColorInversion && TextBox.NeedsColorInversion(color, textBox.TextBoxProps.BackgroundColor))
                {
                    color = TextBox.InvertColor(textBox.TextBoxProps.BackgroundColor);
                }
                using (Brush brush = new SolidBrush(color))
                {
                    nullable2 = ((!textBox.HorizontalText) ? new Rectangle?(new Rectangle(layoutRectangle.Right - offsetY, layoutRectangle.Y + x + num, lineHeight, num2 - num)) : new Rectangle?(new Rectangle(layoutRectangle.X + x + num, layoutRectangle.Y + offsetY - lineHeight, num2 - num, lineHeight)));
                    g.FillRectangle(brush, nullable2.Value);
                }
                if (run.AllowColorInversion && TextBox.NeedsColorInversion(color, run.TextRunProperties.Color))
                {
                    Color color3 = TextBox.InvertColor(run.TextRunProperties.Color);
                    nullable = (uint)(color3.B << 16 | color3.G << 8 | color3.R);
                }
            }
            run.HighlightColor = Color.Empty;
            goto IL_024e;
        }
Esempio n. 24
0
        private static void RenderParagraph(TextBox textBox, Paragraph paragraph, Win32DCSafeHandle hdc, FontCache fontCache, int offsetX, ref int offsetY, Rectangle layoutRectangle, float dpiX)
        {
            List <TextLine> textLines      = paragraph.TextLines;
            IParagraphProps paragraphProps = paragraph.ParagraphProps;
            bool            flag           = textBox.TextBoxProps.Direction == RPLFormat.Directions.LTR;

            RPLFormat.TextAlignments textAlignments = paragraphProps.Alignment;
            if (textAlignments == RPLFormat.TextAlignments.General)
            {
                textAlignments = textBox.TextBoxProps.DefaultAlignment;
                if (!flag)
                {
                    switch (textAlignments)
                    {
                    case RPLFormat.TextAlignments.Right:
                        textAlignments = RPLFormat.TextAlignments.Left;
                        break;

                    case RPLFormat.TextAlignments.Left:
                        textAlignments = RPLFormat.TextAlignments.Right;
                        break;
                    }
                }
            }
            int num  = TextBox.ConvertToPixels(paragraphProps.LeftIndent, dpiX);
            int num2 = TextBox.ConvertToPixels(paragraphProps.RightIndent, dpiX);
            int num3 = TextBox.ConvertToPixels(paragraphProps.HangingIndent, dpiX);

            if (num3 < 0)
            {
                if (flag)
                {
                    num -= num3;
                }
                else
                {
                    num2 -= num3;
                }
            }
            if (paragraphProps.ListLevel > 0)
            {
                int num4 = paragraphProps.ListLevel * TextBox.ConvertToPixels(10.583333f, dpiX);
                if (flag)
                {
                    num += num4;
                }
                else
                {
                    num2 += num4;
                }
            }
            if (textLines == null || textLines.Count == 0)
            {
                offsetY += TextBox.ConvertToPixels(paragraphProps.SpaceBefore, dpiX);
                offsetY += TextBox.ConvertToPixels(paragraphProps.SpaceAfter, dpiX);
            }
            else
            {
                Graphics graphics = null;
                try
                {
                    for (int i = 0; i < textLines.Count; i++)
                    {
                        TextLine textLine = textLines[i];
                        int      ascent   = textLine.GetAscent(hdc, fontCache);
                        textLine.GetDescent(hdc, fontCache);
                        int height = textLine.GetHeight(hdc, fontCache);
                        if (textLine.FirstLine)
                        {
                            offsetY += TextBox.ConvertToPixels(paragraphProps.SpaceBefore, dpiX);
                        }
                        int baselineY = offsetY + ascent;
                        offsetY += height;
                        int num5;
                        switch (textAlignments)
                        {
                        case RPLFormat.TextAlignments.Left:
                            num5 = num;
                            break;

                        case RPLFormat.TextAlignments.Center:
                        {
                            int num6 = 0;
                            num6 = ((!textBox.HorizontalText) ? layoutRectangle.Height : layoutRectangle.Width);
                            num5 = num + (num6 - num - num2) / 2 - textLine.GetWidth(hdc, fontCache) / 2;
                            break;
                        }

                        default:
                            num5 = ((!textBox.HorizontalText) ? (layoutRectangle.Height - num2 - textLine.GetWidth(hdc, fontCache)) : (layoutRectangle.Width - num2 - textLine.GetWidth(hdc, fontCache)));
                            break;
                        }
                        if (textLine.Prefix != null && textLine.Prefix.Count > 0)
                        {
                            int num7 = (!flag) ? (num5 + textLine.GetWidth(hdc, fontCache) + TextBox.ConvertToPixels(4.233333f, dpiX)) : (num5 - TextBox.ConvertToPixels(4.233333f, dpiX) - textLine.GetPrefixWidth(hdc, fontCache));
                            if (num3 < 0)
                            {
                                if (flag && textAlignments == RPLFormat.TextAlignments.Left)
                                {
                                    num7 += num3;
                                }
                                else if (!flag && textAlignments == RPLFormat.TextAlignments.Right)
                                {
                                    num7 -= num3;
                                }
                            }
                            for (int j = 0; j < textLine.Prefix.Count; j++)
                            {
                                TextRun textRun = textLine.Prefix[j];
                                textBox.TextBoxProps.DrawTextRun(textRun, paragraph, hdc, dpiX, fontCache, num7, offsetY, baselineY, height, layoutRectangle);
                                num7 += textRun.GetWidth(hdc, fontCache);
                            }
                        }
                        if (textLine.FirstLine && num3 != 0)
                        {
                            if (flag)
                            {
                                switch (textAlignments)
                                {
                                case RPLFormat.TextAlignments.Left:
                                    num5 += num3;
                                    break;

                                case RPLFormat.TextAlignments.Center:
                                    num5 += num3 / 2;
                                    break;
                                }
                            }
                            else
                            {
                                switch (textAlignments)
                                {
                                case RPLFormat.TextAlignments.Right:
                                    num5 -= num3;
                                    break;

                                case RPLFormat.TextAlignments.Center:
                                    num5 -= num3 / 2;
                                    break;
                                }
                            }
                        }
                        int     prevRunWidth = 0;
                        int     prevRunX     = 0;
                        TextRun prevRun      = null;
                        int     count        = textLine.VisualRuns.Count;
                        for (int k = 0; k < count; k++)
                        {
                            TextRun textRun2 = textLine.VisualRuns[k];
                            int     width    = textRun2.GetWidth(hdc, fontCache, k == count - 1);
                            if (!textRun2.IsHighlightTextRun)
                            {
                                if (width > 0)
                                {
                                    textBox.TextBoxProps.DrawTextRun(textRun2, paragraph, hdc, dpiX, fontCache, num5, offsetY, baselineY, height, layoutRectangle);
                                }
                            }
                            else
                            {
                                bool flag2 = (flag && k + 1 == count) || (!flag && k == 0);
                                if (width > 0 || flag2)
                                {
                                    if (graphics == null)
                                    {
                                        graphics = Graphics.FromHdc(hdc.Handle);
                                    }
                                    TextBox.RenderHighlightedTextRun(textBox, paragraph, textRun2, prevRun, hdc, graphics, fontCache, dpiX, num5, offsetY, baselineY, height, layoutRectangle, width, prevRunWidth, prevRunX, flag2, textLine.LastLine);
                                }
                            }
                            prevRunX     = num5;
                            prevRunWidth = width;
                            num5        += width;
                            prevRun      = textRun2;
                        }
                        if (textLine.LastLine)
                        {
                            offsetY += TextBox.ConvertToPixels(paragraphProps.SpaceAfter, dpiX);
                        }
                    }
                }
                finally
                {
                    if (graphics != null)
                    {
                        graphics.Dispose();
                        graphics = null;
                    }
                }
            }
        }
Esempio n. 25
0
 public static void Render(TextBox textBox, List <Paragraph> paragraphs, Win32DCSafeHandle hdc, FontCache fontCache, PointF offset, RectangleF layoutRectangle, float dpiX, bool unitsInMM)
 {
     if (paragraphs != null && paragraphs.Count != 0)
     {
         Rectangle layoutRectangle2;
         Point     point;
         if (unitsInMM)
         {
             layoutRectangle2 = new Rectangle(TextBox.ConvertToPixels(layoutRectangle.X, dpiX), TextBox.ConvertToPixels(layoutRectangle.Y, dpiX), TextBox.ConvertToPixels(layoutRectangle.Width, dpiX), TextBox.ConvertToPixels(layoutRectangle.Height, dpiX));
             point            = new Point(TextBox.ConvertToPixels(offset.X, dpiX), TextBox.ConvertToPixels(offset.Y, dpiX));
         }
         else
         {
             layoutRectangle2 = new Rectangle((int)layoutRectangle.X, (int)layoutRectangle.Y, (int)layoutRectangle.Width, (int)layoutRectangle.Height);
             point            = new Point((int)offset.X, (int)offset.Y);
         }
         uint fMode   = Win32.SetTextAlign(hdc, 24u);
         int  iBkMode = Win32.SetBkMode(hdc, 1);
         Win32ObjectSafeHandle win32ObjectSafeHandle = Win32.SelectObject(hdc, Win32ObjectSafeHandle.Zero);
         try
         {
             fontCache.WritingMode = textBox.TextBoxProps.WritingMode;
             int y = point.Y;
             for (int i = 0; i < paragraphs.Count; i++)
             {
                 TextBox.RenderParagraph(textBox, paragraphs[i], hdc, fontCache, point.X, ref y, layoutRectangle2, dpiX);
             }
         }
         finally
         {
             fMode   = Win32.SetTextAlign(hdc, fMode);
             iBkMode = Win32.SetBkMode(hdc, iBkMode);
             if (!win32ObjectSafeHandle.IsInvalid)
             {
                 Win32ObjectSafeHandle win32ObjectSafeHandle2 = Win32.SelectObject(hdc, win32ObjectSafeHandle);
                 win32ObjectSafeHandle2.SetHandleAsInvalid();
                 win32ObjectSafeHandle.SetHandleAsInvalid();
             }
         }
     }
 }
Esempio n. 26
0
 public static void Render(TextBox textBox, List <Paragraph> paragraphs, Win32DCSafeHandle hdc, FontCache fontCache, PointF offset, RectangleF layoutRectangle, float dpiX)
 {
     TextBox.Render(textBox, paragraphs, hdc, fontCache, offset, layoutRectangle, dpiX, true);
 }
Esempio n. 27
0
        public static void Render(TextBox textBox, List <Paragraph> paragraphs, Graphics g, FontCache fontCache, PointF offset, RectangleF layoutRectangle)
        {
            float             dpiX = g.DpiX;
            Win32DCSafeHandle win32DCSafeHandle = new Win32DCSafeHandle(g.GetHdc(), false);

            try
            {
                TextBox.Render(textBox, paragraphs, win32DCSafeHandle, fontCache, offset, layoutRectangle, dpiX);
            }
            finally
            {
                fontCache.ResetGraphics();
                if (!win32DCSafeHandle.IsInvalid)
                {
                    g.ReleaseHdc();
                }
            }
        }
Esempio n. 28
0
 public static List <Paragraph> Flow(TextBox textBox, Win32DCSafeHandle hdc, float dpiX, FontCache fontCache, FlowContext flowContext, bool keepLines, out float height)
 {
     if (!(flowContext.Height <= 0.0) && !(flowContext.Width <= 0.0))
     {
         int                   num                   = TextBox.ConvertToPixels(flowContext.ContentOffset, dpiX);
         int                   pixels                = num;
         TextBoxContext        context               = flowContext.Context;
         RPLFormat.Directions  direction             = textBox.TextBoxProps.Direction;
         List <Paragraph>      list                  = new List <Paragraph>();
         Win32ObjectSafeHandle win32ObjectSafeHandle = Win32.SelectObject(hdc, Win32ObjectSafeHandle.Zero);
         SizeF                 flowContextSize;
         if (textBox.VerticalText)
         {
             flowContext.VerticalCanGrow = textBox.TextBoxProps.CanGrow;
             flowContextSize             = new SizeF((float)TextBox.ConvertToPixels(flowContext.Height, dpiX), (float)TextBox.ConvertToPixels(flowContext.Width, dpiX));
         }
         else
         {
             flowContextSize = new SizeF((float)TextBox.ConvertToPixels(flowContext.Width, dpiX), (float)TextBox.ConvertToPixels(flowContext.Height, dpiX));
         }
         fontCache.WritingMode = textBox.TextBoxProps.WritingMode;
         try
         {
             while (context.ParagraphIndex < textBox.Paragraphs.Count)
             {
                 Paragraph paragraph = textBox.Paragraphs[context.ParagraphIndex];
                 paragraph.OffsetY = num;
                 bool flag = LineBreaker.FlowParagraph(paragraph, direction, hdc, dpiX, fontCache, flowContext, keepLines, flowContextSize, ref pixels);
                 num += paragraph.Height;
                 if (!keepLines)
                 {
                     paragraph.TextLines = null;
                 }
                 if (!flag)
                 {
                     break;
                 }
                 list.Add(paragraph);
                 if ((float)num >= flowContextSize.Height)
                 {
                     if (paragraph.AtEndOfParagraph(context))
                     {
                         context.IncrementParagraph();
                     }
                     break;
                 }
                 context.IncrementParagraph();
             }
             if ((float)num < flowContextSize.Height)
             {
                 flowContext.AtEndOfTextBox = true;
             }
         }
         finally
         {
             if (!win32ObjectSafeHandle.IsInvalid)
             {
                 Win32ObjectSafeHandle win32ObjectSafeHandle2 = Win32.SelectObject(hdc, win32ObjectSafeHandle);
                 win32ObjectSafeHandle2.SetHandleAsInvalid();
                 win32ObjectSafeHandle.SetHandleAsInvalid();
             }
         }
         height = TextBox.ConvertToMillimeters(num, dpiX);
         flowContext.ContentOffset = TextBox.ConvertToMillimeters(pixels, dpiX);
         return(list);
     }
     height = 0f;
     return(null);
 }
Esempio n. 29
0
        private static int FindFoldTextPosition_TextRunTrim(TextRun run, Win32DCSafeHandle hdc, FontCache fontCache, float maxWidth, SCRIPT_LOGATTR?nextCharLogAttr)
        {
            string text = run.Text;
            int    i    = LineBreaker.FindFoldTextPosition_CharacterTrim(run, hdc, fontCache, maxWidth);

            if (i == text.Length && i > 0 && !run.ScriptLogAttr[i - 1].IsWhiteSpace && nextCharLogAttr.HasValue && !nextCharLogAttr.Value.IsWhiteSpace && !nextCharLogAttr.Value.IsSoftBreak)
            {
                i--;
            }
            int num = i;

            if (i > 0)
            {
                if (i < text.Length)
                {
                    while (i > 0 && !run.ScriptLogAttr[i].IsWhiteSpace && !run.ScriptLogAttr[i].IsSoftBreak)
                    {
                        i--;
                    }
                    if (i <= 0)
                    {
                        return(-1);
                    }
                    for (; i < num + 1 && run.ScriptLogAttr[i].IsWhiteSpace; i++)
                    {
                    }
                }
                return(i);
            }
            return(-1);
        }
Esempio n. 30
0
        private static int FindWidthToBreakPosition(TextRun run, Win32DCSafeHandle hdc, FontCache fontCache, float maxWidth, out int width)
        {
            string text = run.Text;

            int[] logicalWidths = run.GetLogicalWidths(hdc, fontCache);
            int   num           = 0;

            width = 0;
            while (true)
            {
                if (num >= text.Length)
                {
                    break;
                }
                if (!((float)(width + logicalWidths[num]) <= maxWidth))
                {
                    if (run.ScriptLogAttr[num].IsWhiteSpace)
                    {
                        break;
                    }
                    if (run.ScriptLogAttr[num].IsSoftBreak)
                    {
                        break;
                    }
                }
                width += logicalWidths[num];
                num++;
            }
            return(num);
        }