protected override Size OnGetRequiredSize(SizeConstraint widthConstraint) { var node = GetValue(NodeField); var status = GetViewStatus(node); TextLayout layout = new TextLayout(); layout.Text = node.Text; var textSize = layout.GetSize(); var maxWidth = widthConstraint.IsConstrained ? widthConstraint.AvailableSize : status.LastRenderWidth; // When in expanded mode, the height of the row depends on the width. Since we don't know the width, // let's use the last width that was used for rendering. if (status.Expanded && maxWidth > 0 && textSize.Width > maxWidth) { layout.Width = maxWidth - addImage.Width - MoreLinkSpacing; textSize = layout.GetSize(); } status.LastCalculatedHeight = textSize.Height; return(new Size(30, textSize.Height)); }
public void TextTrimmingEllipsisHeigthBreak() { // Transform is saved InitBlank(50, 100); var la = new TextLayout(); la.Font = Font.FromName("Arial 12"); // + (12 * Desktop.PrimaryScreen.ScaleFactor).ToString (CultureInfo.InvariantCulture)); la.Text = "One Two Three Four Five Six Seven Eight Nine"; la.Width = 60; la.Trimming = TextTrimming.WordElipsis; la.WrapMode = WrapMode.Word; var s = la.GetSize(); var wSize = s; la.Height = s.Height / 9 * 4; s = la.GetSize(); InitBlank((int)(s.Width + 11), (int)(wSize.Height + 11)); // on Gtk, s.Height differs from la.Height, but not on Wpf context.Rectangle(5.5, 5.5, s.Width, la.Height); context.SetColor(Colors.Blue); context.Stroke(); context.SetColor(Colors.Black); context.DrawTextLayout(la, 5, 5); CheckImage("TextTrimmingEllipsisHeigthBreak.png"); }
protected override Size OnGetPreferredSize(SizeConstraint w, SizeConstraint h) { var size = base.OnGetPreferredSize(w, h); double descriptionWidth = 1; double totalHeight = yBorder * 2 + 1; layout.Text = TitleText; var lsize = layout.GetSize(); totalHeight += lsize.Height; xSpacer = 0; foreach (var pair in Items) { layout.Markup = pair.Key; var w1 = layout.GetSize(); layout.Markup = pair.Value; var w2 = layout.GetSize(); descriptionWidth = System.Math.Max(descriptionWidth, w2.Width); xSpacer = System.Math.Max(xSpacer, w1.Width); totalHeight += w2.Height; } xSpacer += xBorder * 2 + 1; return(new Size(descriptionWidth + xSpacer + xBorder * 2 + 1, totalHeight)); }
protected override void OnDraw(Context cr, Rectangle dirtyRect) { cr.Rectangle(dirtyRect.X, dirtyRect.Y, dirtyRect.Width, dirtyRect.Height); cr.SetColor(editor.ColorStyle.PlainText.Background); cr.Fill(); using (var layout = new TextLayout(this)) { layout.Font = editor.Options.Font; layout.Text = "000,00-00"; double minstatusw, minstatush; var sz = layout.GetSize(); minstatusw = sz.Width; minstatush = sz.Height; var line = editor.GetLine(editor.Caret.Line); var visColumn = line.GetVisualColumn(editor.GetTextEditorData(), editor.Caret.Column); if (visColumn != editor.Caret.Column) { layout.Text = editor.Caret.Line + "," + editor.Caret.Column + "-" + visColumn; } else { layout.Text = editor.Caret.Line + "," + editor.Caret.Column; } double statusw, statush; sz = layout.GetSize(); statusw = sz.Width; statush = sz.Height; statusw = System.Math.Max(statusw, minstatusw); statusw += 8; cr.SetColor(editor.ColorStyle.PlainText.Foreground); cr.DrawTextLayout(layout, WidthRequest - statusw, 0); statusw += 8; layout.Text = (statusText ?? ""); double w, h; sz = layout.GetSize(); w = sz.Width; h = sz.Height; var x = System.Math.Min(0, -w + WidthRequest - editor.TextViewMargin.CharWidth - statusw); cr.SetColor(editor.ColorStyle.PlainText.Foreground); cr.DrawTextLayout(layout, x, 0); if (ShowCaret) { if (editor.TextViewMargin.caretBlink) { cr.Rectangle(w + x, 0, (int)editor.TextViewMargin.CharWidth, (int)editor.LineHeight); cr.Fill(); } } cr.Stroke(); } }
internal bool CalculateLayout(Rectangle cellArea, out TextLayout textLayout, out Rectangle layoutBounds, out Rectangle expanderRect) { // Relayouting is expensive and not required if the size didn't change. Just update the locations in that case. if (!LastRenderBounds.IsEmpty && LastRenderBounds.Contains(LastRenderLayoutBounds) && cellArea.Size == LastRenderBounds.Size) { expanderRect = LastRenderExpanderBounds.Offset(-LastRenderBounds.X, -LastRenderBounds.Y).Offset(cellArea.X, cellArea.Y); layoutBounds = LastRenderLayoutBounds.Offset(-LastRenderBounds.X, -LastRenderBounds.Y).Offset(cellArea.X, cellArea.Y); textLayout = GetUnconstrainedLayout(); textLayout.Width = layoutBounds.Width; return(true); // no resize is required } expanderRect = Rectangle.Zero; layoutBounds = cellArea; layoutBounds.X += ImageSize + ImagePadding; layoutBounds.Width -= ImagePadding + DefaultInformationContainerWidth; textLayout = GetUnconstrainedLayout(); var textSize = textLayout.GetSize(); if (textSize.Width > layoutBounds.Width || NewLineCharIndex > -1) { layoutBounds.Width -= (ImageSize + ImagePadding); layoutBounds.Width = Math.Max(MinLayoutWidth, layoutBounds.Width); textLayout.Width = layoutBounds.Width; textLayout.Height = Expanded ? -1 : cellArea.Height; textSize = textLayout.GetSize(); var expanderX = layoutBounds.Right + ImagePadding; if (expanderX > 0) { expanderRect = new Rectangle(expanderX, cellArea.Y + ((CollapsedLayoutHeight - BuildExpandIcon.Height) * .5), BuildExpandIcon.Width, BuildExpandIcon.Height); } } layoutBounds.Height = textSize.Height; layoutBounds.Y += LayoutYPadding; expanderRect.Y += LayoutYPadding; // check that the text still fits into the cell if (!cellArea.Contains(layoutBounds)) { return(false); // resize required } // if the cell is too large, we need to resize it else if (Expanded && Math.Abs(layoutBounds.Height - LayoutYPadding - cellArea.Height) > 1) { return(false); // resize required } return(true); }
/// <summary> /// Draws the title using the Drawing Context, Origin (x,y) and scale /// </summary> /// <returns> /// The Size required for the title /// </returns> /// TODO: Add a MeasureTitle routine, since can measure TextLayout now /// Size DrawTitle(Context ctx, Point origin, double scale) { ctx.Save(); ctx.SetColor(TitleColor); Font scaled_font; if (AutoScaleTitle) { scaled_font = TitleFont.WithScaledSize(scale); } else { scaled_font = TitleFont; } TextLayout layout = new TextLayout(); layout.Font = scaled_font; layout.Text = Title; Size titleSize = layout.GetSize(); origin.X -= titleSize.Width / 2; ctx.DrawTextLayout(layout, origin); ctx.Restore(); return(titleSize); }
public void SomeText(Context ctx) { var size = new Size(1000, 3000); var font = Font.FromName("Tahoma 10"); var stringPos = new Point(0, 0); var xInc = 10; var yInc = 3; ctx.SetColor(Colors.LawnGreen); var rnd = new Random(); while ((stringPos.Y < size.Height) && (stringPos.X < size.Width)) { string s = "[No " + rnd.Next(10000).ToString("#,##0") + " *-|-]"; var textLayout = new TextLayout(); textLayout.Font = font; textLayout.Width = size.Width - stringPos.X; textLayout.Trimming = TextTrimming.WordElipsis; textLayout.Text = s; ctx.DrawTextLayout(textLayout, stringPos); ctx.Stroke(); ctx.Fill(); stringPos.Y += textLayout.GetSize().Height + yInc; stringPos.X += xInc; } }
protected override void OnDraw(Context ctx, Rectangle cellArea) { ManagePackagesSearchResultViewModel packageViewModel = GetValue(PackageField); if (packageViewModel == null) { return; } FillCellBackground(ctx); UpdateTextColor(ctx); DrawCheckBox(ctx, packageViewModel, cellArea); DrawPackageImage(ctx, cellArea); double packageIdWidth = cellArea.Width - packageDescriptionPadding.HorizontalSpacing - packageDescriptionLeftOffset; // Package download count. if (packageViewModel.HasDownloadCount) { var downloadCountTextLayout = new TextLayout(); downloadCountTextLayout.Text = packageViewModel.GetDownloadCountOrVersionDisplayText(); Size size = downloadCountTextLayout.GetSize(); Point location = new Point(cellArea.Right - packageDescriptionPadding.Right, cellArea.Top + packageDescriptionPadding.Top); Point downloadLocation = location.Offset(-size.Width, 0); ctx.DrawTextLayout(downloadCountTextLayout, downloadLocation); packageIdWidth = downloadLocation.X - cellArea.Left - packageIdRightHandPaddingWidth - packageDescriptionPadding.HorizontalSpacing - packageDescriptionLeftOffset; } // Package Id. // Use the package id and not the package title to prevent a pango crash if the title // contains Chinese characters. var packageIdTextLayout = new TextLayout(); packageIdTextLayout.Font = packageIdTextLayout.Font.WithSize(packageIdFontSize); packageIdTextLayout.Markup = packageViewModel.GetIdMarkup(); packageIdTextLayout.Trimming = TextTrimming.WordElipsis; Size packageIdTextSize = packageIdTextLayout.GetSize(); packageIdTextLayout.Width = packageIdWidth; ctx.DrawTextLayout( packageIdTextLayout, cellArea.Left + packageDescriptionPadding.Left + packageDescriptionLeftOffset, cellArea.Top + packageDescriptionPadding.Top); // Package description. var descriptionTextLayout = new TextLayout(); descriptionTextLayout.Font = descriptionTextLayout.Font.WithSize(packageDescriptionFontSize); descriptionTextLayout.Width = cellArea.Width - packageDescriptionPadding.HorizontalSpacing - packageDescriptionLeftOffset; descriptionTextLayout.Height = cellArea.Height - packageIdTextSize.Height - packageDescriptionPadding.VerticalSpacing; descriptionTextLayout.Text = packageViewModel.Summary; descriptionTextLayout.Trimming = TextTrimming.Word; ctx.DrawTextLayout( descriptionTextLayout, cellArea.Left + packageDescriptionPadding.Left + packageDescriptionLeftOffset, cellArea.Top + packageIdTextSize.Height + packageDescriptionPaddingHeight + packageDescriptionPadding.Top); }
public static Size MeasureString(string text, Font font, double w) { if (text == null) { return(Size.Zero); } if (text.Length < 2000) { if (measure == null) { measure = new TextLayout(); } lock (measure) { measure.Width = w; measure.Font = font; measure.Text = text; return(measure.GetSize()); } } else { return(MeasureStringDefault(text, font, w)); } }
protected override void OnDraw(Context ctx, Rectangle dirtyRect) { base.OnDraw(ctx, dirtyRect); ctx.SetColor(Colors.White); ctx.Rectangle(this.Bounds); ctx.Fill(); if (!this.editmode) { var value = this.owner.GetValue(item); string txt; if (this.item.TypeConverter.CanConvertTo(this.item as ITypeDescriptorContext, typeof(string))) { txt = item.TypeConverter.ConvertToString(this.item as ITypeDescriptorContext, value); } else { txt = value?.ToString(); } ctx.SetColor(Colors.Black); var tl = new TextLayout() { Text = txt, Font = PropertyGrid.PropertyFont, Trimming = TextTrimming.WordElipsis, Width = this.Bounds.Width, Height = this.Bounds.Height, TextAlignment = Alignment.Start }; var ts = tl.GetSize(); var xy = new Point(0, (this.Bounds.Height - ts.Height) * .5); ctx.DrawTextLayout(tl, xy); } }
void DrawText(Context ctx, TextLayout tl, ref double x, ref double y) { var dx = 0d; var s = tl.GetSize(); switch (tl.TextAlignment) { case Alignment.Center: dx = Math.Round((tl.Width - s.Width) / 2); break; case Alignment.End: dx = tl.Width - s.Width; break; } var rect = new Rectangle(x + dx, y, s.Width, s.Height).Inflate(0.5, 0.5); ctx.SetLineWidth(1); ctx.SetColor(Colors.Blue); ctx.Rectangle(rect); ctx.Stroke(); ctx.SetColor(Colors.Black); ctx.DrawTextLayout(tl, x, y); y += s.Height + 20; if (y > 400) { y = 180; x += 150; } }
/// <summary> /// Renders the pager text using the results of SetupPagerText. /// </summary> protected virtual void RenderPagerText(Context context, TextLayout layout, Rectangle bounds) { var s = layout.GetSize(); context.SetColor(PagerTextColor); context.DrawTextLayout(layout, bounds.X + (bounds.Width - s.Width) / 2, bounds.Y + (bounds.Height - s.Height) / 2); }
public void Reload() { var message = Node.Message; NewLineCharIndex = message.IndexOf('\n'); if (!Expanded && NewLineCharIndex > -1) { message = message.Substring(0, NewLineCharIndex); } if (layout.Text != message) { layout.Text = message; // PERF: calculate the height in collapsed state only once // The layout height of the first line is always the same and we want // the first line to be always aligned to the left icon in all states. // The heights calculated here will be used to always report the static // height in collapsed state and to calculate the padding. if (!Expanded || CollapsedLayoutHeight < 0) { layout.Trimming = TextTrimming.WordElipsis; var textSize = layout.GetSize(); CollapsedLayoutHeight = textSize.Height; CollapsedRowHeight = Math.Max(textSize.Height, ImageSize); LayoutYPadding = (CollapsedRowHeight - CollapsedLayoutHeight) * .5; } } layout.Trimming = Expanded ? TextTrimming.Word : TextTrimming.WordElipsis; }
void CalcLayout(out TextLayout layout, out Rectangle cellArea, out Rectangle expanderRect) { var node = GetValue(NodeField); var status = GetViewStatus(node); expanderRect = Rectangle.Zero; cellArea = Bounds; layout = new TextLayout(); layout.Text = node.Text; var textSize = layout.GetSize(); if (textSize.Width > cellArea.Width) { layout.Width = Math.Max(1, cellArea.Width - addImage.Width - MoreLinkSpacing); if (!status.Expanded) { layout.Trimming = TextTrimming.WordElipsis; } var expanderX = cellArea.Right - addImage.Width; if (expanderX > 0) { expanderRect = new Rectangle(expanderX, cellArea.Y, addImage.Width, addImage.Height); } } }
protected override Size OnGetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint) { var size = layout.GetSize(); if (!window.HideCodeSegmentPreviewInformString) { var size2 = informLayout.GetSize(); window.PreviewInformStringHeight = size2.Height; size.Width = System.Math.Max(size.Width, size2.Width); size.Height += size2.Height; } Rectangle geometry = ScreenBounds; return(new Size(System.Math.Max(1, System.Math.Min(size.Width + 3, geometry.Width * 2 / 5)), System.Math.Max(1, System.Math.Min(size.Height + 3, geometry.Height * 2 / 5)))); }
public override void Render(ISurface surface) { var contextSurface = (ContextSurface)surface; if (string.IsNullOrEmpty(this.Text)) { return; } var matrix = contextSurface.Matrix; if (matrix.M11 < 0.2d || matrix.M22 < 0.2d) { return; } var ctx = contextSurface.Context; var style = this.Style; var shape = this.OuterShape; var font = Style.Font; if (AlignText && shape is IVectorShape) { var vector = ((IVectorShape)shape).Data; var f = ctx.DpiFactor(); var width = Vector.Length(vector); var height = Math.Ceiling(font.Size); var text = new TextLayout(ctx); text.Trimming = TextTrimming.WordElipsis; text.Text = this.Text; text.Font = font; var size = text.GetSize(); width = Math.Min(size.Width, width); height = Math.Max(size.Height, height); text.Width = width; text.Height = height; var c = new Point( (vector.Start.X + (vector.End.X - vector.Start.X) / 2d), (vector.Start.Y + (vector.End.Y - vector.Start.Y) / 2d)); ctx.Save(); ctx.Translate(c.X, c.Y); ctx.Rotate(Vector.Angle(vector)); ctx.SetColor(style.TextColor); ctx.SetLineWidth(1); ctx.DrawTextLayout(text, -width / 2d, -height / 2d); ctx.Restore(); } else { var rect = shape.BoundsRect.Padding(Style.Padding); ContextPainterExtensions.DrawText(ctx, rect, this.Text, font, style.TextColor); } }
public void CalculateSize(double defaultWidth = -1) { var sz = layout.GetSize(); double h = sz.Height, w = sz.Width; if (!HideCodeSegmentPreviewInformString) { sz = informLayout.GetSize(); PreviewInformStringHeight = sz.Height; w = System.Math.Max(w, sz.Width); h += sz.Height; } var geometry = ParentWindow.Screen.VisibleBounds; WidthRequest = System.Math.Max(1, System.Math.Min(w + 3, geometry.Width * 2 / 5)); HeightRequest = System.Math.Max(1, System.Math.Min(h + 3, geometry.Height * 2 / 5)); }
Rectangle GetPagerBounds(TextLayout layout, Rectangle region) { var textSize = layout.GetSize(); var width = textSize.Width + Styles.PopoverWindow.PagerTriangleSize * 2 + 20; var height = Styles.PopoverWindow.PagerHeight; return(new Rectangle(region.X + region.Width - width, 0, width, height)); }
protected override void OnDraw(Context ctx, Rectangle cellArea) { PackageViewModel packageViewModel = GetValue(PackageField); if (packageViewModel == null) { return; } FillCellBackground(ctx); UpdateTextColor(ctx); DrawCheckBox(ctx, packageViewModel, cellArea); DrawPackageImage(ctx, cellArea); double packageIdWidth = cellArea.Width - packageDescriptionPadding.HorizontalSpacing - packageDescriptionLeftOffset; // Package download count. if (packageViewModel.HasDownloadCount) { var downloadCountTextLayout = new TextLayout(); downloadCountTextLayout.Text = packageViewModel.GetDownloadCountDisplayText(); Size size = downloadCountTextLayout.GetSize(); Point location = new Point(cellArea.Right - packageDescriptionPadding.Right, cellArea.Top + packageDescriptionPadding.Top); Point downloadLocation = location.Offset(-size.Width, 0); ctx.DrawTextLayout(downloadCountTextLayout, downloadLocation); packageIdWidth = downloadLocation.X - cellArea.Left - packageIdRightHandPaddingWidth - packageDescriptionPadding.HorizontalSpacing - packageDescriptionLeftOffset; } // Package Id. var packageIdTextLayout = new TextLayout(); packageIdTextLayout.Markup = packageViewModel.GetNameMarkup(); packageIdTextLayout.Trimming = TextTrimming.WordElipsis; Size packageIdTextSize = packageIdTextLayout.GetSize(); packageIdTextLayout.Width = packageIdWidth; ctx.DrawTextLayout( packageIdTextLayout, cellArea.Left + packageDescriptionPadding.Left + packageDescriptionLeftOffset, cellArea.Top + packageDescriptionPadding.Top); // Package description. var descriptionTextLayout = new TextLayout(); descriptionTextLayout.Font = descriptionTextLayout.Font.WithScaledSize(0.9); descriptionTextLayout.Width = cellArea.Width - packageDescriptionPadding.HorizontalSpacing - packageDescriptionLeftOffset; descriptionTextLayout.Height = cellArea.Height - packageIdTextSize.Height - packageDescriptionPadding.VerticalSpacing; descriptionTextLayout.Text = packageViewModel.Summary; descriptionTextLayout.Trimming = TextTrimming.Word; ctx.DrawTextLayout( descriptionTextLayout, cellArea.Left + packageDescriptionPadding.Left + packageDescriptionLeftOffset, cellArea.Top + packageIdTextSize.Height + packageDescriptionPaddingHeight + packageDescriptionPadding.Top); }
protected override Size OnGetRequiredSize() { var layout = new TextLayout(); layout.Text = "W"; Size size = layout.GetSize(); return(new Size(0, size.Height + namePadding.VerticalSpacing)); }
protected override Size OnGetPreferredSize(SizeConstraint w, SizeConstraint h) { base.OnGetPreferredSize(w, h); UpdateLayout(); var size = layout.GetSize(); size.Width += indent; return(size); }
double ComputeCharWidth() { var textLayout = new TextLayout(); textLayout.Font = editor.Options.EditorFont; textLayout.Text = "W"; return(textLayout.GetSize().Width); }
double ComputeLineHeight() { var textLayout = new TextLayout(); textLayout.Font = editor.Options.EditorFont; textLayout.Text = "W"; return(textLayout.GetSize().Height); }
internal protected override void OptionsChanged() { var layout = new TextLayout(Editor); layout.Font = Editor.Options.Font; layout.Text = "."; // int height; charWidth = layout.GetSize().Width; layout.Dispose(); }
protected override Size OnGetRequiredSize() { var layout = new TextLayout(); layout.Text = "W"; layout.Font = layout.Font.WithSize(packageDescriptionFontSize); Size size = layout.GetSize(); return(new Size(CellWidth, size.Height * linesDisplayedCount + packageDescriptionPaddingHeight + packageDescriptionPadding.VerticalSpacing)); }
internal protected override void OptionsChanged() { var layout = new TextLayout(Editor); layout.Font = Editor.Options.Font; layout.Text = string.Format("0{0:X}", Data.Length) + "_"; // int height; width = layout.GetSize().Width; layout.Dispose(); }
internal protected override void OptionsChanged() { backgroundColor = editor.ColorStyle.IndicatorMargin.Color; separatorColor = editor.ColorStyle.IndicatorMarginSeparator.Color; layout.Font = editor.Options.Font; layout.Text = "!"; marginWidth = layout.GetSize().Width; //layout.GetPixelSize (out tmp, out this.marginWidth); marginWidth *= 12; marginWidth /= 10; }
void DrawCursorLabel(Context ctx, ChartCursor cursor) { ctx.SetColor(cursor.Color); int x, y; GetPoint(cursor.Value, cursor.Value, out x, out y); if (cursor.Dimension == AxisDimension.X) { string text; if (cursor.LabelAxis != null) { double minStep = GetMinTickStep(cursor.Dimension); TickEnumerator tenum = cursor.LabelAxis.GetTickEnumerator(minStep); tenum.Init(cursor.Value); text = tenum.CurrentLabel; } else { text = GetValueLabel(cursor.Dimension, cursor.Value); } if (text != null && text.Length > 0) { TextLayout layout = new TextLayout(ctx); layout.Font = chartFont; layout.Text = text; Size ts = layout.GetSize(); double tl = x - ts.Width / 2; double tt = top + 4; if (tl + ts.Width + 2 >= left + width) { tl = left + width - ts.Width - 1; } if (tl < left + 1) { tl = left + 1; } ctx.SetColor(Colors.White); ctx.Rectangle(tl - 1, tt - 1, ts.Width + 2, ts.Height + 2); ctx.Fill(); ctx.Rectangle(tl - 2, tt - 2, ts.Width + 3, ts.Height + 3); ctx.SetColor(Colors.Black); ctx.DrawTextLayout(layout, tl, tt); } } else { throw new NotSupportedException(); } }
internal protected override void OptionsChanged() { var layout = new TextLayout(Editor); layout.Font = Editor.Options.Font; layout.Text = "!"; // int tmp; this.marginWidth = layout.GetSize().Height; marginWidth *= 12; marginWidth /= 10; layout.Dispose(); }
protected override Size OnGetPreferredSize(SizeConstraint w, SizeConstraint h) { base.OnGetPreferredSize(w, h); double descriptionWidth = 1; double totalHeight = yTitleBorder * 2 + yDescriptionBorder * 2 + 1; titleLayout.Text = TitleText; var size1 = titleLayout.GetSize(); totalHeight += size1.Height; xSpacer = 0; var size2 = descriptionLayout.GetSize(); totalHeight += size2.Height; xSpacer = System.Math.Max(size1.Width, size2.Width); xSpacer += xDescriptionBorder * 2 + 1; return(new Size(triangleWidth + descriptionWidth + xSpacer, totalHeight)); }