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

            try
            {
                win32ObjectSafeHandle2 = Win32.SelectObject(hdc, win32ObjectSafeHandle);
                Win32.MoveToEx(hdc, m_startPoint.X, m_startPoint.Y, IntPtr.Zero);
                Win32.LineTo(hdc, m_endPoint.X, m_endPoint.Y);
            }
            finally
            {
                if (!win32ObjectSafeHandle2.IsInvalid)
                {
                    Win32.SelectObject(hdc, win32ObjectSafeHandle2).SetHandleAsInvalid();
                    win32ObjectSafeHandle2.SetHandleAsInvalid();
                }
                if (!win32ObjectSafeHandle.IsInvalid)
                {
                    win32ObjectSafeHandle.Close();
                    win32ObjectSafeHandle = null;
                }
            }
        }
Esempio n. 2
0
        internal void Render(Graphics g, RectangleF rectangle, PointF offset, IEnumerable <RTSelectionHighlight> highlights, bool unitsInMM)
        {
            List <Paragraph> rTParagraphs = RTParagraphs;

            if (rTParagraphs == null || rTParagraphs.Count == 0)
            {
                return;
            }
            using (RevertingDeviceContext revertingDeviceContext = new RevertingDeviceContext(g, Dpi))
            {
                Win32DCSafeHandle hdc = revertingDeviceContext.Hdc;
                if (highlights != null)
                {
                    _ = RTTextbox.TextBoxProps.Direction;
                    foreach (RTSelectionHighlight highlight in highlights)
                    {
                        if (!HighlightStartLessThanOrEqualToEnd(highlight.SelectionStart, highlight.SelectionEnd))
                        {
                            TextBoxContext selectionStart = highlight.SelectionStart;
                            highlight.SelectionStart = highlight.SelectionEnd;
                            highlight.SelectionEnd   = selectionStart;
                        }
                        TextRun   run;
                        CaretInfo caretInfo = MapLocation(hdc, highlight.SelectionStart, relativeToRun: true, moveCaretToNextLine: true, out run);
                        TextRun   run2;
                        CaretInfo caretInfo2 = MapLocation(hdc, highlight.SelectionEnd, relativeToRun: true, moveCaretToNextLine: true, out run2);
                        if (caretInfo != null && caretInfo2 != null && run != null && run2 != null)
                        {
                            SetHighlighting(rTParagraphs, hdc, highlight, run, run2, caretInfo.Position.X, caretInfo2.Position.X);
                        }
                    }
                }
                Rectangle rect = (!unitsInMM) ? Rectangle.Round(rectangle) : new Rectangle(TextBox.ConvertToPixels(rectangle.X, m_dpi), TextBox.ConvertToPixels(rectangle.Y, m_dpi), TextBox.ConvertToPixels(rectangle.Width, m_dpi), TextBox.ConvertToPixels(rectangle.Height, m_dpi));
                revertingDeviceContext.XForm.Transform(ref rect);
                Win32ObjectSafeHandle win32ObjectSafeHandle = Win32.CreateRectRgn(rect.Left - 1, rect.Top - 1, rect.Right + 1, rect.Bottom + 1);
                if (!win32ObjectSafeHandle.IsInvalid)
                {
                    try
                    {
                        if (Win32.SelectClipRgn(hdc, win32ObjectSafeHandle) == 0)
                        {
                            Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                        }
                    }
                    finally
                    {
                        win32ObjectSafeHandle.Close();
                    }
                }
                TextBox.Render(RTTextbox, rTParagraphs, hdc, FontCache, offset, rectangle, m_dpi, unitsInMM);
                if (Win32.SelectClipRgn(hdc, Win32ObjectSafeHandle.Zero) == 0)
                {
                    Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                }
            }
        }
Esempio n. 3
0
 internal void SelectFontObject(Win32DCSafeHandle hdc, Win32ObjectSafeHandle hFont)
 {
     if (hdc != m_selectedHdc)
     {
         m_selectedHdc  = hdc;
         m_selectedFont = Win32ObjectSafeHandle.Zero;
     }
     if (hFont != m_selectedFont)
     {
         Win32.SelectObject(hdc, hFont).SetHandleAsInvalid();
         m_selectedFont = hFont;
     }
 }
Esempio n. 4
0
 private void Dispose(bool disposing)
 {
     if (disposing && m_font != null)
     {
         m_font.Dispose();
         m_font = null;
     }
     if (m_hfont != null && !m_hfont.IsInvalid)
     {
         m_hfont.Close();
         m_hfont = null;
     }
     ScriptCache.Close();
 }
Esempio n. 5
0
        internal 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)
            {
                return;
            }
            Rectangle layoutRectangle2;
            Point     point;

            if (!unitsInMM)
            {
                layoutRectangle2 = new Rectangle((int)layoutRectangle.X, (int)layoutRectangle.Y, (int)layoutRectangle.Width, (int)layoutRectangle.Height);
                point            = new Point((int)offset.X, (int)offset.Y);
            }
            else
            {
                layoutRectangle2 = new Rectangle(ConvertToPixels(layoutRectangle.X, dpiX), ConvertToPixels(layoutRectangle.Y, dpiX), ConvertToPixels(layoutRectangle.Width, dpiX), ConvertToPixels(layoutRectangle.Height, dpiX));
                point            = new Point(ConvertToPixels(offset.X, dpiX), ConvertToPixels(offset.Y, dpiX));
            }
            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 offsetY = point.Y;
                for (int i = 0; i < paragraphs.Count; i++)
                {
                    RenderParagraph(textBox, paragraphs[i], hdc, fontCache, point.X, ref offsetY, layoutRectangle2, dpiX);
                }
            }
            finally
            {
                fMode   = Win32.SetTextAlign(hdc, fMode);
                iBkMode = Win32.SetBkMode(hdc, iBkMode);
                if (!win32ObjectSafeHandle.IsInvalid)
                {
                    Win32.SelectObject(hdc, win32ObjectSafeHandle).SetHandleAsInvalid();
                    win32ObjectSafeHandle.SetHandleAsInvalid();
                }
            }
        }
Esempio n. 6
0
        internal static List <Paragraph> Flow(TextBox textBox, Win32DCSafeHandle hdc, float dpiX, FontCache fontCache, FlowContext flowContext, bool keepLines, out float height)
        {
            if (flowContext.Height <= 0f || flowContext.Width <= 0f)
            {
                height = 0f;
                return(null);
            }
            int            num           = TextBox.ConvertToPixels(flowContext.ContentOffset, dpiX);
            int            contentOffset = 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)
            {
                flowContextSize = new SizeF(TextBox.ConvertToPixels(flowContext.Width, dpiX), TextBox.ConvertToPixels(flowContext.Height, dpiX));
            }
            else
            {
                flowContext.VerticalCanGrow = textBox.TextBoxProps.CanGrow;
                flowContextSize             = new SizeF(TextBox.ConvertToPixels(flowContext.Height, dpiX), TextBox.ConvertToPixels(flowContext.Width, dpiX));
            }
            fontCache.WritingMode = textBox.TextBoxProps.WritingMode;
            try
            {
                while (context.ParagraphIndex < textBox.Paragraphs.Count)
                {
                    Paragraph paragraph = textBox.Paragraphs[context.ParagraphIndex];
                    paragraph.OffsetY = num;
                    bool num2 = FlowParagraph(paragraph, direction, hdc, dpiX, fontCache, flowContext, keepLines, flowContextSize, ref contentOffset);
                    num += paragraph.Height;
                    if (!keepLines)
                    {
                        paragraph.TextLines = null;
                    }
                    if (!num2)
                    {
                        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)
                {
                    Win32.SelectObject(hdc, win32ObjectSafeHandle).SetHandleAsInvalid();
                    win32ObjectSafeHandle.SetHandleAsInvalid();
                }
            }
            height = TextBox.ConvertToMillimeters(num, dpiX);
            flowContext.ContentOffset = TextBox.ConvertToMillimeters(contentOffset, dpiX);
            return(list);
        }
Esempio n. 7
0
 internal void ResetGraphics()
 {
     m_selectedHdc  = Win32DCSafeHandle.Zero;
     m_selectedFont = Win32ObjectSafeHandle.Zero;
 }
Esempio n. 8
0
 internal static extern int SelectClipRgn(Win32DCSafeHandle hdc, Win32ObjectSafeHandle hrgn);
Esempio n. 9
0
 internal static extern bool SetViewportOrgEx(Win32DCSafeHandle hdc, int X, int Y, Win32ObjectSafeHandle lpPoint);
Esempio n. 10
0
 internal static extern int DeleteObject(Win32ObjectSafeHandle hObject);
Esempio n. 11
0
 internal static extern Win32ObjectSafeHandle SelectObject(Win32DCSafeHandle hDC, Win32ObjectSafeHandle gdiobj);