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 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); } }
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); }
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); }
private CaretInfo MapLocation(Graphics g, TextBoxContext location, bool relativeToRun, bool moveCaretToNextLine, out TextRun run) { Win32DCSafeHandle win32DCSafeHandle = null; bool flag = false; try { if (g == null) { flag = true; g = Graphics.FromHwnd(IntPtr.Zero); } win32DCSafeHandle = new Win32DCSafeHandle(g.GetHdc(), false); return(this.MapLocation(win32DCSafeHandle, location, relativeToRun, moveCaretToNextLine, out run)); } finally { if (!win32DCSafeHandle.IsInvalid) { g.ReleaseHdc(); } if (flag) { g.Dispose(); g = null; } } }
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); } }
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; } } }
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); }
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); }
public int GetPrefixWidth(Win32DCSafeHandle hdc, FontCache fontCache) { if (this.m_prefix == null) { return(0); } this.CalculateDimensions(hdc, fontCache, true); return(this.m_prefixWidth); }
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); } }
public void Render(Graphics g, RectangleF rectangle, PointF offset, IEnumerable <RTSelectionHighlight> highlights, bool unitsInMM) { List <Paragraph> rTParagraphs = this.RTParagraphs; if (rTParagraphs != null && rTParagraphs.Count != 0) { using (RevertingDeviceContext revertingDeviceContext = new RevertingDeviceContext(g, this.Dpi)) { Win32DCSafeHandle hdc = revertingDeviceContext.Hdc; if (highlights != null) { RPLFormat.Directions direction = this.RTTextbox.TextBoxProps.Direction; foreach (RTSelectionHighlight highlight in highlights) { if (!RichTextRenderer.HighlightStartLessThanOrEqualToEnd(highlight.SelectionStart, highlight.SelectionEnd)) { TextBoxContext selectionStart = highlight.SelectionStart; highlight.SelectionStart = highlight.SelectionEnd; highlight.SelectionEnd = selectionStart; } TextRun textRun = default(TextRun); CaretInfo caretInfo = this.MapLocation(hdc, highlight.SelectionStart, true, true, out textRun); TextRun textRun2 = default(TextRun); CaretInfo caretInfo2 = this.MapLocation(hdc, highlight.SelectionEnd, true, true, out textRun2); if (caretInfo != null && caretInfo2 != null && textRun != null && textRun2 != null) { this.SetHighlighting(rTParagraphs, hdc, highlight, textRun, textRun2, caretInfo.Position.X, caretInfo2.Position.X); } } } Rectangle rectangle2 = (!unitsInMM) ? Rectangle.Round(rectangle) : new Rectangle(TextBox.ConvertToPixels(rectangle.X, this.m_dpi), TextBox.ConvertToPixels(rectangle.Y, this.m_dpi), TextBox.ConvertToPixels(rectangle.Width, this.m_dpi), TextBox.ConvertToPixels(rectangle.Height, this.m_dpi)); revertingDeviceContext.XForm.Transform(ref rectangle2); Win32ObjectSafeHandle win32ObjectSafeHandle = Win32.CreateRectRgn(rectangle2.Left - 1, rectangle2.Top - 1, rectangle2.Right + 1, rectangle2.Bottom + 1); if (!win32ObjectSafeHandle.IsInvalid) { try { if (Win32.SelectClipRgn(hdc, win32ObjectSafeHandle) == 0) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } } finally { win32ObjectSafeHandle.Close(); } } TextBox.Render(this.RTTextbox, rTParagraphs, hdc, this.FontCache, offset, rectangle, this.m_dpi, unitsInMM); if (Win32.SelectClipRgn(hdc, Win32ObjectSafeHandle.Zero) == 0) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } } } }
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)); }
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); }
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); }
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; }
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; } }
private CaretInfo MapLocation(Win32DCSafeHandle hdc, TextBoxContext location, bool relativeToRun, bool moveCaretToNextLine, out TextRun run) { CaretInfo caretInfo = null; run = null; int lineYOffset = default(int); int lineHeight = default(int); int iCP = default(int); bool isFirstLine = default(bool); bool isLastLine = default(bool); Point paragraphAndRunCoordinates = this.GetParagraphAndRunCoordinates(hdc, location, moveCaretToNextLine, out lineYOffset, out lineHeight, out run, out iCP, out isFirstLine, out isLastLine); if (run != null) { GlyphData glyphData = run.GlyphData; GlyphShapeData glyphScriptShapeData = glyphData.GlyphScriptShapeData; int num = 0; if (glyphData != null && run.CharacterCount > 0) { int num2 = Win32.ScriptCPtoX(iCP, false, run.CharacterCount, glyphScriptShapeData.GlyphCount, glyphScriptShapeData.Clusters, glyphScriptShapeData.VisAttrs, glyphData.Advances, ref run.SCRIPT_ANALYSIS, ref num); if (Win32.Failed(num2)) { Marshal.ThrowExceptionForHR(num2); } } caretInfo = new CaretInfo(); CachedFont cachedFont = run.GetCachedFont(hdc, this.FontCache); caretInfo.Height = cachedFont.GetHeight(hdc, this.FontCache); caretInfo.Ascent = cachedFont.GetAscent(hdc, this.FontCache); caretInfo.Descent = cachedFont.GetDescent(hdc, this.FontCache); caretInfo.LineHeight = lineHeight; caretInfo.LineYOffset = lineYOffset; caretInfo.IsFirstLine = isFirstLine; caretInfo.IsLastLine = isLastLine; List <Paragraph> rTParagraph = this.RTParagraphs; int y = paragraphAndRunCoordinates.Y - caretInfo.Ascent; if (relativeToRun) { caretInfo.Position = new Point(num, y); } else { caretInfo.Position = new Point(paragraphAndRunCoordinates.X + num, y); } } return(caretInfo); }
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(); } } }
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(); } } }
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); }
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(); } } } }
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); }
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); } }
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; } }
private void SetupGraphics(float dpi) { this.m_graphics.PageUnit = GraphicsUnit.Pixel; this.m_graphics.PageScale = 1f; this.m_hdc = new Win32DCSafeHandle(this.m_graphics.GetHdc(), false); this.m_oldXForm = default(Win32.XFORM); if (this.m_matrix != null) { this.m_xForm = new Win32.XFORM(this.m_matrix, this.m_pageUnits, dpi); this.m_oldMode = Win32.SetGraphicsMode(this.m_hdc, 2); if (!Win32.GetWorldTransform(this.m_hdc, ref this.m_oldXForm)) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } if (!Win32.SetWorldTransform(this.m_hdc, ref this.m_xForm)) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } } else { this.m_xForm = Win32.XFORM.Identity; } }
public void ResetGraphics() { this.m_selectedHdc = Win32DCSafeHandle.Zero; this.m_selectedFont = Win32ObjectSafeHandle.Zero; }
private Point GetParagraphAndRunCoordinates(Win32DCSafeHandle hdc, TextBoxContext location, bool moveCaretToNextLine, out int lineYOffset, out int lineHeight, out TextRun textRun, out int textRunCharacterIndex, out bool isFirstLine, out bool isLastLine) { int num = 0; int textRunIndex = location.TextRunIndex; textRunCharacterIndex = location.TextRunCharacterIndex; lineYOffset = 0; lineHeight = 0; textRun = null; isFirstLine = true; isLastLine = true; List <Paragraph> rTParagraphs = this.RTParagraphs; if (rTParagraphs != null && location.ParagraphIndex < rTParagraphs.Count) { Paragraph paragraph = rTParagraphs[location.ParagraphIndex]; int num2 = paragraph.OffsetY + TextBox.ConvertToPixels(paragraph.ParagraphProps.SpaceBefore, this.Dpi); int num3 = TextBox.ConvertToPixels(paragraph.ParagraphProps.LeftIndent, this.Dpi); int num4 = TextBox.ConvertToPixels(paragraph.ParagraphProps.RightIndent, this.Dpi); int num5 = TextBox.ConvertToPixels(paragraph.ParagraphProps.HangingIndent, this.Dpi); bool flag = this.m_rttextbox.TextBoxProps.Direction == RPLFormat.Directions.LTR; if (num5 < 0) { if (flag) { num3 -= num5; } else { num4 -= num5; } } int listLevel = paragraph.ParagraphProps.ListLevel; if (listLevel > 0) { int num6 = listLevel * TextBox.ConvertToPixels(10.583333f, this.Dpi); if (flag) { num3 += num6; } else { num4 += num6; } } for (int i = 0; i < paragraph.TextLines.Count; i++) { TextLine textLine = paragraph.TextLines[i]; int descent = textLine.GetDescent(hdc, this.FontCache); lineHeight = textLine.GetHeight(hdc, this.FontCache); lineYOffset = num2; num2 += lineHeight; RPLFormat.TextAlignments textAlignments = paragraph.ParagraphProps.Alignment; if (textAlignments == RPLFormat.TextAlignments.General) { textAlignments = this.m_rttextbox.TextBoxProps.DefaultAlignment; if (!flag) { switch (textAlignments) { case RPLFormat.TextAlignments.Left: textAlignments = RPLFormat.TextAlignments.Right; break; case RPLFormat.TextAlignments.Right: textAlignments = RPLFormat.TextAlignments.Left; break; } } } switch (textAlignments) { case RPLFormat.TextAlignments.Center: num = num3 + (this.WidthInPX - num3 - num4) / 2 - textLine.GetWidth(hdc, this.FontCache) / 2; break; case RPLFormat.TextAlignments.Right: num = this.WidthInPX - textLine.GetWidth(hdc, this.FontCache) - num4; break; default: num = num3; break; } if (textLine.FirstLine && num5 != 0) { if (flag) { switch (textAlignments) { case RPLFormat.TextAlignments.Left: num += num5; break; case RPLFormat.TextAlignments.Center: num += num5 / 2; break; } } else { switch (textAlignments) { case RPLFormat.TextAlignments.Right: num -= num5; break; case RPLFormat.TextAlignments.Center: num -= num5 / 2; break; } } } int count = textLine.VisualRuns.Count; for (int j = 0; j < count; num += textRun.GetWidth(hdc, this.FontCache), j++) { textRun = textLine.VisualRuns[j]; if (textRun.TextRunProperties.IndexInParagraph == textRunIndex && textRunCharacterIndex >= textRun.CharacterIndexInOriginal) { bool flag2 = (moveCaretToNextLine || textRun.CharacterCount <= 0 || textRun.Text[textRun.CharacterCount - 1] != '\n') ? (textRunCharacterIndex <= textRun.CharacterIndexInOriginal + textRun.CharacterCount) : (textRunCharacterIndex < textRun.CharacterIndexInOriginal + textRun.CharacterCount); if (!flag2 && (i + 1 != paragraph.TextLines.Count || j + 1 != count)) { continue; } if (moveCaretToNextLine && textRunCharacterIndex == textRun.CharacterIndexInOriginal + textRun.CharacterCount && j + 1 == count && i + 1 < paragraph.TextLines.Count) { location = location.Clone(); if (paragraph.TextLines[i + 1].VisualRuns[0].TextRunProperties.IndexInParagraph != textRunIndex) { location.TextRunIndex++; location.TextRunCharacterIndex = 0; } Point paragraphAndRunCoordinates = this.GetParagraphAndRunCoordinates(hdc, location, false, out lineYOffset, out lineHeight, out textRun, out textRunCharacterIndex, out isFirstLine, out isLastLine); textRunCharacterIndex = Math.Max(textRunCharacterIndex - 1, 0); return(paragraphAndRunCoordinates); } textRunCharacterIndex -= textRun.CharacterIndexInOriginal; isFirstLine = textLine.FirstLine; isLastLine = textLine.LastLine; return(new Point(num, num2 - descent)); } } } textRun = null; return(Point.Empty); } return(Point.Empty); }
private TextBoxContext GetParagraphAndRunIndex(Win32DCSafeHandle hdc, Paragraph paragraph, TextLine line, int x, int lineWidth, bool lastParagraph, out TextRun run, ref int runX, out bool atEndOfLine) { atEndOfLine = false; run = null; int count = line.VisualRuns.Count; int num = 0; while (num < count) { run = line.VisualRuns[num]; int width = run.GetWidth(hdc, this.FontCache, num == count - 1); if (runX - width > 0 && num + 1 != count) { runX -= width; num++; continue; } TextBoxContext textBoxContext; if (runX - width > 0) { atEndOfLine = true; if (run.ScriptAnalysis.fLayoutRTL == 1 && x >= lineWidth) { run = line.VisualRuns[count - 1]; textBoxContext = new TextBoxContext(); textBoxContext.TextRunIndex = run.TextRunProperties.IndexInParagraph; textBoxContext.TextRunCharacterIndex = run.CharacterIndexInOriginal; return(textBoxContext); } } int num2 = 0; int characterCount = run.CharacterCount; if (characterCount > 0) { if (run.ScriptAnalysis.fLayoutRTL == 0 && num + 1 == count) { goto IL_00f0; } if (run.ScriptAnalysis.fLayoutRTL == 1 && num == 0) { goto IL_00f0; } if (num == 0 && (run.Text[0] == '\r' || run.Text[0] == '\n')) { num2 = -1; } } else if (lastParagraph && line.LastLine && !line.FirstLine) { num2 = 1; } goto IL_025d; IL_025d: textBoxContext = new TextBoxContext(); textBoxContext.TextRunIndex = run.TextRunProperties.IndexInParagraph; textBoxContext.TextRunCharacterIndex = run.CharacterIndexInOriginal + num2; return(textBoxContext); IL_00f0: if (width <= 0) { string text = run.Text; if (characterCount > 1 && text[characterCount - 2] == '\r' && text[characterCount - 1] == '\n') { num2 = ((run.ScriptAnalysis.fLayoutRTL != 0) ? (-1) : (-2)); } else if (text[characterCount - 1] == '\n' && run.ScriptAnalysis.fLayoutRTL == 0) { if (num > 0) { run = line.VisualRuns[num - 1]; if (run.CharacterCount > 0 && run.Text[run.CharacterCount - 1] == '\r') { num2 = -1; } } else { num2 = -1; } } } else if (num + 1 == count && (run.Text[characterCount - 1] == '\r' || run.Text[characterCount - 1] == '\n')) { num2 = -1; } else if (num == 0 && (run.Text[0] == '\r' || run.Text[0] == '\n')) { num2 = -1; } goto IL_025d; } return(null); }