//used only in old layouts public SizeF GetTextSize(SizeF proposedSize, bool autoFitInProposedSize, TextParams textParams) { SizeF res = SizeF.Empty; StringFormat sf = textParams.CreateStringFormat(); string textToMeasure = textParams.text; //p.p. 29.07.09 //fix very strange bug with Hebrew and FitToGrid Renedering hint lock (MeasurementGraphics.SyncObject) { Graphics g = RadGdiGraphics.MeasurementGraphics; g.TextRenderingHint = textParams.textRenderingHint; //StringFormat sf = this.CreateStringFormat(); string measureableString = GetHelperString(textToMeasure); if (autoFitInProposedSize) { res = g.MeasureString(measureableString, textParams.font, proposedSize, sf); } else { res = g.MeasureString(measureableString, textParams.font, 0, sf); } //g.Dispose(); } sf.Dispose(); this.measuredSize = res; return(res); }
public void PaintPrimitive(Telerik.WinControls.Paint.IGraphics graphics, float angle, System.Drawing.SizeF scale, TextParams textParams) { if (this.isDirty) { this.isDirty = false; this.TextBlock = TinyHTMLParsers.Parse(textParams); } RectangleF paintingRectangle = textParams.paintingRectangle; StringFormat format = textParams.CreateStringFormat(); this.TextBlock.PaintFormatTextBlock(graphics, paintingRectangle, true, format, TextFormatFlags.Default, textParams.textWrap, textParams.ClipText); format.Dispose(); }
public SizeF GetTextSize(SizeF proposedSize, TextParams textParams) { SizeF sizeF = SizeF.Empty; if (string.IsNullOrEmpty(textParams.text) || (double)proposedSize.Width == 0.0) { return(SizeF.Empty); } StringFormat stringFormat = textParams.CreateStringFormat(); int width = float.IsInfinity(proposedSize.Width) ? int.MaxValue : (int)Math.Floor((double)proposedSize.Width); if (textParams.textOrientation == Orientation.Vertical) { width = float.IsInfinity(proposedSize.Height) ? int.MaxValue : (int)Math.Floor((double)proposedSize.Height); } string text = textParams.text; if (text.Length > RadGdiGraphics.GdiStringLengthLimit) { text = text.Substring(0, RadGdiGraphics.GdiStringLengthLimit); } if (textParams.useCompatibleTextRendering) { lock (MeasurementGraphics.SyncObject) { Graphics measurementGraphics = RadGdiGraphics.MeasurementGraphics; measurementGraphics.TextRenderingHint = textParams.textRenderingHint; sizeF = measurementGraphics.MeasureString(text, textParams.font ?? Control.DefaultFont, width, stringFormat); if (float.IsNaN(sizeF.Width) || float.IsNaN(sizeF.Height)) { sizeF = SizeF.Empty; } sizeF.Height = (float)Math.Round((double)sizeF.Height); sizeF.Width = (float)Math.Ceiling((double)sizeF.Width); } } else if (!string.IsNullOrEmpty(text)) { TextFormatFlags textFormatFlags = this.CreateTextFormatFlags(textParams); sizeF = (SizeF)TextRenderer.MeasureText(text, textParams.font, new Size(width, int.MaxValue), textFormatFlags); } stringFormat.Dispose(); this.measuredSize = sizeF; return(sizeF); }
public SizeF GetTextSize( SizeF proposedSize, bool autoFitInProposedSize, TextParams textParams) { SizeF sizeF = SizeF.Empty; StringFormat stringFormat = textParams.CreateStringFormat(); string s = textParams.text.Length <= RadGdiGraphics.GdiStringLengthLimit ? textParams.text : textParams.text.Substring(0, RadGdiGraphics.GdiStringLengthLimit); lock (MeasurementGraphics.SyncObject) { Graphics measurementGraphics = RadGdiGraphics.MeasurementGraphics; measurementGraphics.TextRenderingHint = textParams.textRenderingHint; string helperString = this.GetHelperString(s); sizeF = !autoFitInProposedSize?measurementGraphics.MeasureString(helperString, textParams.font, 0, stringFormat) : measurementGraphics.MeasureString(helperString, textParams.font, proposedSize, stringFormat); } stringFormat.Dispose(); this.measuredSize = sizeF; return(sizeF); }
public void PaintPrimitive( IGraphics graphics, float angle, SizeF scale, TextParams textParams) { if (this.isDirty) { this.isDirty = false; this.TextBlock = TinyHTMLParsers.Parse(textParams); } RectangleF paintingRectangle = textParams.paintingRectangle; StringFormat stringFormat = textParams.CreateStringFormat(); Graphics underlayGraphics = (Graphics)graphics.UnderlayGraphics; TextRenderingHint textRenderingHint = underlayGraphics.TextRenderingHint; underlayGraphics.TextRenderingHint = textParams.textRenderingHint; this.TextBlock.PaintFormatTextBlock(graphics, paintingRectangle, true, stringFormat, TextFormatFlags.Default, textParams.textWrap, textParams.ClipText); underlayGraphics.TextRenderingHint = textRenderingHint; stringFormat.Dispose(); }
public SizeF GetTextSize(SizeF proposedSize, TextParams textParams) { SizeF res = SizeF.Empty; if (string.IsNullOrEmpty(textParams.text) || proposedSize.Width == 0) { return(SizeF.Empty); } StringFormat sf = textParams.CreateStringFormat(); int avaibleWidth = (int)(float.IsInfinity(proposedSize.Width) ? int.MaxValue : Math.Floor(proposedSize.Width)); string textToMeasure = textParams.text; if (textParams.useCompatibleTextRendering) { //p.p. 29.07.09 //fix very strange bug with Hebrew and FitToGrid Renedering hint lock (MeasurementGraphics.SyncObject) { Graphics g = RadGdiGraphics.MeasurementGraphics; g.TextRenderingHint = textParams.textRenderingHint; res = g.MeasureString(textToMeasure, textParams.font, avaibleWidth, sf); res.Height = (float)Math.Round(res.Height); res.Width = (float)Math.Ceiling(res.Width); //g.Dispose(); } } else if (!string.IsNullOrEmpty(textToMeasure)) { TextFormatFlags flags = this.CreateTextFormatFlags(textParams); res = TextRenderer.MeasureText(textToMeasure, textParams.font, new Size(avaibleWidth, int.MaxValue), flags); } sf.Dispose(); this.measuredSize = res; return(res); }
// helper method which changes the whitespaces with a dummy character public StringFormat CreateStringFormat() { TextParams textParams = this.CreateTextParams(); return(textParams.CreateStringFormat()); }