Exemple #1
0
        public void Draw(Win32DCSafeHandle hdc, int lineThickness, uint rgbColor)
        {
            if (lineThickness < 1)
            {
                lineThickness = 1;
            }
            Win32.LOGBRUSH lOGBRUSH = default(Win32.LOGBRUSH);
            lOGBRUSH.lbColor = rgbColor;
            lOGBRUSH.lbHatch = 0;
            lOGBRUSH.lbStyle = 0u;
            Win32ObjectSafeHandle win32ObjectSafeHandle  = Win32.ExtCreatePen(66048u, (uint)lineThickness, ref lOGBRUSH, 0u, null);
            Win32ObjectSafeHandle win32ObjectSafeHandle2 = Win32ObjectSafeHandle.Zero;

            try
            {
                win32ObjectSafeHandle2 = Win32.SelectObject(hdc, win32ObjectSafeHandle);
                Win32.MoveToEx(hdc, this.m_startPoint.X, this.m_startPoint.Y, IntPtr.Zero);
                Win32.LineTo(hdc, this.m_endPoint.X, this.m_endPoint.Y);
            }
            finally
            {
                if (!win32ObjectSafeHandle2.IsInvalid)
                {
                    Win32ObjectSafeHandle win32ObjectSafeHandle3 = Win32.SelectObject(hdc, win32ObjectSafeHandle2);
                    win32ObjectSafeHandle3.SetHandleAsInvalid();
                    win32ObjectSafeHandle2.SetHandleAsInvalid();
                }
                if (!win32ObjectSafeHandle.IsInvalid)
                {
                    win32ObjectSafeHandle.Close();
                    win32ObjectSafeHandle = null;
                }
            }
        }
Exemple #2
0
 public void SelectFontObject(Win32DCSafeHandle hdc, Win32ObjectSafeHandle hFont)
 {
     if (hdc != this.m_selectedHdc)
     {
         this.m_selectedHdc  = hdc;
         this.m_selectedFont = Win32ObjectSafeHandle.Zero;
     }
     if (hFont != this.m_selectedFont)
     {
         Win32ObjectSafeHandle win32ObjectSafeHandle = Win32.SelectObject(hdc, hFont);
         win32ObjectSafeHandle.SetHandleAsInvalid();
         this.m_selectedFont = hFont;
     }
 }
Exemple #3
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();
             }
         }
     }
 }
Exemple #4
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);
 }
        public void ShapeAndPlace(Win32DCSafeHandle hdc, FontCache fontCache)
        {
            bool verticalFont = false;

            if (fontCache.AllowVerticalFont)
            {
                verticalFont = this.HasEastAsianChars;
            }
            if (this.m_cachedFont == null)
            {
                this.m_cachedFont = fontCache.GetFont(this.m_textRunProps, this.GetCharset(), verticalFont);
                this.FallbackFont = false;
            }
            CachedFont cachedFont = this.m_cachedFont;
            bool       flag       = false;
            bool       flag2      = false;
            string     text       = this.m_text;
            int        num        = Convert.ToInt32((double)text.Length * 1.5 + 16.0);

            this.m_cachedGlyphData = new GlyphData(num, text.Length);
            GlyphShapeData glyphScriptShapeData = this.m_cachedGlyphData.GlyphScriptShapeData;
            int            num2 = Win32.ScriptShape(IntPtr.Zero, ref this.m_cachedFont.ScriptCache, text, text.Length, num, ref this.SCRIPT_ANALYSIS, glyphScriptShapeData.Glyphs, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, ref glyphScriptShapeData.GlyphCount);

            if (num2 == -2147483638)
            {
                flag = true;
                fontCache.SelectFontObject(hdc, this.m_cachedFont.Hfont);
                num2 = Win32.ScriptShape(hdc, ref this.m_cachedFont.ScriptCache, text, text.Length, num, ref this.SCRIPT_ANALYSIS, glyphScriptShapeData.Glyphs, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, ref glyphScriptShapeData.GlyphCount);
            }
            if (num2 == -2147024882)
            {
                num = text.Length * 3;
                this.m_cachedGlyphData = new GlyphData(num, text.Length);
                glyphScriptShapeData   = this.m_cachedGlyphData.GlyphScriptShapeData;
                num2 = Win32.ScriptShape(hdc, ref this.m_cachedFont.ScriptCache, text, text.Length, num, ref this.SCRIPT_ANALYSIS, glyphScriptShapeData.Glyphs, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, ref glyphScriptShapeData.GlyphCount);
            }
            if (!this.FallbackFont)
            {
                if (num2 == -2147220992)
                {
                    int num3 = 0;
                    num3 = ((!this.m_itemizedScriptId.HasValue) ? this.ScriptAnalysis.eScript : this.m_itemizedScriptId.Value);
                    this.m_cachedFont = fontCache.GetFallbackFont(this.m_textRunProps, this.GetCharset(), num3, verticalFont);
                    fontCache.SelectFontObject(hdc, this.m_cachedFont.Hfont);
                    flag  = true;
                    flag2 = true;
                    num2  = Win32.ScriptShape(hdc, ref this.m_cachedFont.ScriptCache, text, text.Length, num, ref this.SCRIPT_ANALYSIS, glyphScriptShapeData.Glyphs, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, ref glyphScriptShapeData.GlyphCount);
                }
                else if (this.HasEastAsianChars)
                {
                    if (!flag)
                    {
                        fontCache.SelectFontObject(hdc, this.m_cachedFont.Hfont);
                        flag = true;
                    }
                    Win32.SCRIPT_FONTPROPERTIES sCRIPT_FONTPROPERTIES = default(Win32.SCRIPT_FONTPROPERTIES);
                    sCRIPT_FONTPROPERTIES.cBytes = 16;
                    num2 = Win32.ScriptGetFontProperties(hdc, ref this.m_cachedFont.ScriptCache, ref sCRIPT_FONTPROPERTIES);
                    short wgDefault = sCRIPT_FONTPROPERTIES.wgDefault;
                    int   num4      = 0;
                    num4 = ((!this.m_itemizedScriptId.HasValue) ? this.ScriptAnalysis.eScript : this.m_itemizedScriptId.Value);
                    int num5 = 0;
                    while (num5 < glyphScriptShapeData.GlyphCount)
                    {
                        if (glyphScriptShapeData.Glyphs[num5] != wgDefault)
                        {
                            num5++;
                            continue;
                        }
                        this.m_cachedFont = fontCache.GetFallbackFont(this.m_textRunProps, this.GetCharset(), num4, verticalFont);
                        this.m_cachedFont.DefaultGlyph = wgDefault;
                        fontCache.SelectFontObject(hdc, this.m_cachedFont.Hfont);
                        flag  = true;
                        flag2 = true;
                        num2  = Win32.ScriptShape(hdc, ref this.m_cachedFont.ScriptCache, text, text.Length, num, ref this.SCRIPT_ANALYSIS, glyphScriptShapeData.Glyphs, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, ref glyphScriptShapeData.GlyphCount);
                        break;
                    }
                }
            }
            if (num2 == -2147220992)
            {
                this.m_cachedFont = cachedFont;
                if (!flag || flag2)
                {
                    Win32ObjectSafeHandle win32ObjectSafeHandle = Win32.SelectObject(hdc, this.m_cachedFont.Hfont);
                    win32ObjectSafeHandle.SetHandleAsInvalid();
                    flag = true;
                }
                flag2 = false;
                this.SetUndefinedScript();
                num2 = Win32.ScriptShape(hdc, ref this.m_cachedFont.ScriptCache, text, text.Length, num, ref this.SCRIPT_ANALYSIS, glyphScriptShapeData.Glyphs, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, ref glyphScriptShapeData.GlyphCount);
            }
            if (Win32.Failed(num2))
            {
                Marshal.ThrowExceptionForHR(num2);
            }
            if (flag2)
            {
                this.FallbackFont = true;
            }
            this.m_cachedGlyphData.TrimToGlyphCount();
            this.m_cachedGlyphData.ScaleFactor = this.m_cachedFont.ScaleFactor;
            this.TextScriptPlace(hdc, flag, fontCache);
        }