/// <summary> /// Measures the string. /// </summary> /// <param name="text">The text to measure.</param> /// <param name="font">The text font.</param> /// <returns></returns> public override VectorD3D MeasureString(string text, FontX3D font) { var scale = font.Font.Size / FontSizeForCaching; double offsetX = 0; bool isFirst = true; CharacterGeometry geo = null; foreach (var c in text) { geo = GetCharacterGeometry(font.Font, c); if (isFirst) { isFirst = false; if (geo.LeftSideBearing < 0) { offsetX = -geo.LeftSideBearing; } } offsetX += geo.AdvanceWidth; } if (null != geo && geo.RightSideBearing < 0) { offsetX += -geo.RightSideBearing; } return(new VectorD3D(offsetX * scale, null == geo ? 0 : geo.LineSpacing *scale, font.Depth)); }
public override bool CopyFrom(object obj) { var isCopied = base.CopyFrom(obj); if (isCopied && !object.ReferenceEquals(this, obj)) { var from = obj as TextGraphic; if (from != null) { _text = from._text; _font = from._font; _textBrush = from._textBrush; _background = from._background == null ? null : (IBackgroundStyle)from._background.Clone(); if (null != _background) { _background.ParentObject = this; } _lineSpacingFactor = from._lineSpacingFactor; // don't clone the cached items _isStructureInSync = false; _isMeasureInSync = false; } } return(isCopied); }
/// <summary> /// Gets information about the font. /// </summary> /// <param name="font">The font.</param> /// <returns>Font information.</returns> public override FontInfo GetFontInformation(FontX3D font) { var typeface = WpfFontManager.ToWpf(font.Font); var scale = font.Font.Size; return(new FontInfo(typeface.FontFamily.LineSpacing * scale, typeface.CapsHeight * scale, typeface.FontFamily.LineSpacing * scale - typeface.CapsHeight * scale, font.Font.Size)); }
private void EhFontDepth_SelectionChangeCommitted(object sender, System.Windows.DependencyPropertyChangedEventArgs e) { if (FontX != null) { FontX3D = FontX3D.WithDepth(_cbFontDepth.SelectedQuantityAsValueInPoints); OnSelectedFontChanged(); } }
public TextGraphic(PointD3D graphicPosition, string text, FontX3D textFont, NamedColor textColor) : base(new ItemLocationDirectAutoSize()) { SetPosition(graphicPosition, Main.EventFiring.Suppressed); Font = textFont; Text = text; Color = textColor; }
public FontInfo GetFontInfo(FontX3D id) { if (!_fontInfoDictionary.TryGetValue(id, out var result)) { result = FontManager3D.Instance.GetFontInformation(id); _fontInfoDictionary.Add(id, result); } return(result); }
public FontInfo GetFontInfo(FontX3D id) { FontInfo result; if (!_fontInfoDictionary.TryGetValue(id, out result)) { result = FontManager3D.Instance.GetFontInformation(id); _fontInfoDictionary.Add(id, result); } return result; }
public override VectorD3D MeasureItem(IGraphicsContext3D g, FontX3D font, Altaxo.Data.AltaxoVariant mtick, PointD3D morg) { SplitInFirstPartAndExponent(mtick, out var firstpart, out var mant, out var middelpart, out var exponent); var size1 = g.MeasureString(_prefix + firstpart + middelpart, font, PointD3D.Empty); var size2 = g.MeasureString(exponent, font, PointD3D.Empty); var size3 = g.MeasureString(_suffix, font, PointD3D.Empty); return(new VectorD3D(size1.X + size2.X + size3.X, size1.Y, font.Depth)); }
public TextGraphic(Altaxo.Main.Properties.IReadOnlyPropertyBag context) : base(new ItemLocationDirectAutoSize()) { if (null == context) { context = PropertyExtensions.GetPropertyContextOfProject(); } _font = GraphDocument.GetDefaultFont(context); _textBrush = Materials.GetSolidMaterial(GraphDocument.GetDefaultForeColor(context)); }
public MeasuredLabelItem(IGraphicsContext3D g, FontX3D font1, FontX3D font2, string firstpart, string exponent, string lastpart, double maxexposize) { _firstpart = firstpart; _exponent = exponent; _lastpart = lastpart; _font1 = font1; _font2 = font2; _size1 = g.MeasureString(_firstpart, _font1, PointD3D.Empty); _size2 = g.MeasureString(_exponent, _font2, new PointD3D(_size1.X, 0, 0)); _size3 = g.MeasureString(_lastpart, _font1, PointD3D.Empty); _rightPadding = maxexposize - _size2.X; }
public MeasuredLabelItem(IGraphicsContext3D g, FontX3D font, string itemtext, double lineSpacing, Alignment horizontalAlignment, Alignment verticalAlignment, Alignment textBlockAligment) { _text = itemtext.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); _stringSize = new VectorD3D[_text.Length]; _font = font; _horizontalAlignment = horizontalAlignment; _verticalAlignment = verticalAlignment; _textBlockAligment = textBlockAligment; _lineSpacing = lineSpacing; _size = VectorD3D.Empty; var bounds = RectangleD3D.Empty; var position = PointD3D.Empty; for (int i = 0; i < _text.Length; ++i) { _stringSize[i] = g.MeasureString(_text[i], _font, PointD3D.Empty); bounds = bounds.WithRectangleIncluded(new RectangleD3D(position, _stringSize[i])); position = position.WithYPlus(-_stringSize[i].Y * _lineSpacing); } _size = bounds.Size; }
/// <summary> /// Measures a couple of items and prepares them for being drawn. /// </summary> /// <param name="g">Graphics context.</param> /// <param name="font">Font used.</param> /// <param name="items">Array of items to be drawn.</param> /// <returns>An array of <see cref="IMeasuredLabelItem" /> that can be used to determine the size of each item and to draw it.</returns> public virtual IMeasuredLabelItem[] GetMeasuredItems(IGraphicsContext3D g, FontX3D font, AltaxoVariant[] items) { string[] titems = FormatItems(items); if (!string.IsNullOrEmpty(_prefix) || !string.IsNullOrEmpty(_suffix)) { for (int i = 0; i < titems.Length; ++i) { titems[i] = _prefix + titems[i] + _suffix; } } var litems = new MeasuredLabelItem[titems.Length]; FontX3D localfont = font; for (int i = 0; i < titems.Length; ++i) { litems[i] = new MeasuredLabelItem(g, localfont, titems[i]); } return(litems); }
/// <summary> /// Measures a couple of items and prepares them for being drawn. /// </summary> /// <param name="g">Graphics context.</param> /// <param name="font">Font used.</param> /// <param name="items">Array of items to be drawn.</param> /// <returns>An array of <see cref="IMeasuredLabelItem" /> that can be used to determine the size of each item and to draw it.</returns> public override IMeasuredLabelItem[] GetMeasuredItems(IGraphicsContext3D g, FontX3D font, AltaxoVariant[] items) { string[] titems = FormatItems(items); if (!string.IsNullOrEmpty(_prefix) || !string.IsNullOrEmpty(_suffix)) { for (int i = 0; i < titems.Length; ++i) { titems[i] = _prefix + titems[i] + _suffix; } } var litems = new MeasuredLabelItem[titems.Length]; FontX3D localfont = font; for (int i = 0; i < titems.Length; ++i) { litems[i] = new MeasuredLabelItem(g, localfont, titems[i], _relativeLineSpacing, Alignment.Near, Alignment.Near, _textBlockAlignment); } return(litems); }
public override void DrawItem(IGraphicsContext3D g, IMaterial brush, FontX3D font, Altaxo.Data.AltaxoVariant item, PointD3D morg) { SplitInFirstPartAndExponent(item, out var firstpart, out var mant, out var middelpart, out var exponent); var size1 = g.MeasureString(_prefix + firstpart + middelpart, font, morg); g.DrawString(_prefix + firstpart + middelpart, font, brush, morg); var orginalY = morg.Y; morg = morg + new VectorD3D(size1.X, size1.Y, 0); var font2 = font.WithSize(font.Size * 2 / 3.0); g.DrawString(exponent, font2, brush, morg); if (!string.IsNullOrEmpty(_suffix)) { var shiftX = g.MeasureString(exponent, font2, morg).X; morg = new PointD3D(morg.X + shiftX, orginalY, morg.Z); } if (!string.IsNullOrEmpty(_suffix)) { g.DrawString(_suffix, font, brush, morg); } }
public void ScaleFont(double scale) { FontId = FontId.WithSize(scale * FontId.Size); }
/// <summary> /// Draws the item to a specified location. /// </summary> /// <param name="g">Graphics context.</param> /// <param name="brush">Brush used to draw the item.</param> /// <param name="font">Font used to draw the item.</param> /// <param name="item">The item to draw.</param> /// <param name="morg">The location where the item is drawn to.</param> public virtual void DrawItem(IGraphicsContext3D g, IMaterial brush, FontX3D font, AltaxoVariant item, PointD3D morg) { string text = _prefix + FormatItem(item) + _suffix; g.DrawString(text, font, brush, morg); }
/// <summary>Measures the string with the appropriate generic typographic format.</summary> /// <param name="text">The text to measure.</param> /// <param name="font">The font used.</param> /// <returns>Width and height of the text packed into a <see cref="VectorD3D"/> structure.</returns> public static VectorD3D MeasureString(string text, FontX3D font) { return(FontManager3D.Instance.MeasureString(text, font)); }
public StyleContext(FontX3D font, IMaterial brush) { FontId = font; this.brush = brush; }
public override bool CopyFrom(object obj) { var isCopied = base.CopyFrom(obj); if (isCopied && !object.ReferenceEquals(this, obj)) { var from = obj as TextGraphic; if (from != null) { this._text = from._text; this._font = from._font; this._textBrush = from._textBrush; this._background = from._background == null ? null : (IBackgroundStyle)from._background.Clone(); if (null != _background) _background.ParentObject = this; this._lineSpacingFactor = from._lineSpacingFactor; // don't clone the cached items this._isStructureInSync = false; this._isMeasureInSync = false; } } return isCopied; }
public void SetFontStyle(FontXStyle style) { FontId = FontId.WithStyle(style); }
public virtual bool CopyFrom(object obj) { if (object.ReferenceEquals(this, obj)) return true; var from = obj as AxisLabelStyle; if (null == from) return false; using (var suspendToken = SuspendGetToken()) { _cachedAxisStyleInfo = from._cachedAxisStyleInfo; _font = from._font; _alignmentX = from._alignmentX; _alignmentY = from._alignmentY; _alignmentZ = from._alignmentZ; _brush = from._brush; _automaticRotationShift = from._automaticRotationShift; _offsetX = from._offsetX; _offsetY = from._offsetY; _offsetZ = from._offsetZ; _rotationX = from._rotationX; _rotationY = from._rotationY; _rotationZ = from._rotationZ; ChildCopyToMember(ref _backgroundStyle, from._backgroundStyle); ChildCopyToMember(ref _labelFormatting, from._labelFormatting); _labelSide = from._labelSide; _prefixText = from._prefixText; _postfixText = from._postfixText; ChildCopyToMember(ref _suppressedLabels, from._suppressedLabels); EhSelfChanged(EventArgs.Empty); suspendToken.Resume(); } return true; }
public TextGraphic(Altaxo.Main.Properties.IReadOnlyPropertyBag context) : base(new ItemLocationDirectAutoSize()) { if (null == context) context = PropertyExtensions.GetPropertyContextOfProject(); _font = GraphDocument.GetDefaultFont(context); _textBrush = Materials.GetSolidMaterial(GraphDocument.GetDefaultForeColor(context)); }
public virtual void DrawString(string text, FontX3D font, IMaterial brush, PointD3D point, Alignment alignmentX, Alignment alignmentY, Alignment alignmentZ) { VectorD3D stringSize = new VectorD3D(0, 0, font.Depth); // depth is already known, for this we don't need to call MeasureString if (alignmentX != Alignment.Near || alignmentY != Alignment.Near) stringSize = FontManager3D.Instance.MeasureString(text, font); switch (alignmentX) { case Alignment.Near: break; case Alignment.Center: point = point.WithXPlus(-0.5 * stringSize.X); break; case Alignment.Far: point = point.WithXPlus(-stringSize.X); break; default: break; } switch (alignmentY) { case Alignment.Near: break; case Alignment.Center: point = point.WithYPlus(-0.5 * stringSize.Y); break; case Alignment.Far: point = point.WithYPlus(-stringSize.Y); break; default: break; } switch (alignmentZ) { case Alignment.Near: break; case Alignment.Center: point = point.WithZPlus(-0.5 * stringSize.Z); break; case Alignment.Far: point = point.WithZPlus(-stringSize.Z); break; default: break; } DrawString(text, font, brush, point); }
public virtual void DrawString(string text, FontX3D font, IMaterial brush, PointD3D point) { var txt = new SolidText(text, font); /* VectorD3D stringSize = new VectorD3D(0, 0, font.Depth); if (stringAlignment.AlignmentX != Alignment.Near || stringAlignment.AlignmentY != Alignment.Near) stringSize = FontManager3D.Instance.MeasureString(text, font); switch (stringAlignment.AlignmentX) { case Alignment.Near: break; case Alignment.Center: point = point.WithXPlus(-0.5 * stringSize.X); break; case Alignment.Far: point = point.WithXPlus(-stringSize.X); break; default: break; } switch (stringAlignment.AlignmentY) { case Alignment.Near: break; case Alignment.Center: point = point.WithYPlus(-0.5 * stringSize.Y); break; case Alignment.Far: point = point.WithYPlus(-stringSize.Y); break; default: break; } switch (stringAlignment.AlignmentZ) { case Alignment.Near: break; case Alignment.Center: point = point.WithZPlus(-0.5 * stringSize.Z); break; case Alignment.Far: point = point.WithZPlus(-stringSize.Z); break; default: break; } */ var buffers = GetPositionNormalIndexedTriangleBuffer(brush); var offset = buffers.IndexedTriangleBuffer.VertexCount; if (null != buffers.PositionNormalIndexedTriangleBuffer) { var buf = buffers.PositionNormalIndexedTriangleBuffer; txt.AddWithNormals( FontManager3D.Instance.GetCharacterGeometry, (position, normal) => buf.AddTriangleVertex(position.X + point.X, position.Y + point.Y, position.Z + point.Z, normal.X, normal.Y, normal.Z), (i0, i1, i2) => buf.AddTriangleIndices(i0, i1, i2), ref offset); } else if (null != buffers.PositionNormalColorIndexedTriangleBuffer) { var buf = buffers.PositionNormalColorIndexedTriangleBuffer; var color = brush.Color.Color; var r = color.ScR; var g = color.ScG; var b = color.ScB; var a = color.ScA; txt.AddWithNormals( FontManager3D.Instance.GetCharacterGeometry, (position, normal) => buf.AddTriangleVertex(position.X + point.X, position.Y + point.Y, position.Z + point.Z, normal.X, normal.Y, normal.Z, r, g, b, a), (i0, i1, i2) => buf.AddTriangleIndices(i0, i1, i2), ref offset); } else if (null != buffers.PositionNormalUVIndexedTriangleBuffer) { throw new NotImplementedException("Texture on a text is not supported yet"); } else { throw new NotImplementedException("Unexpected type of buffer: " + buffers.IndexedTriangleBuffer.GetType().ToString()); } }
public virtual VectorD3D MeasureString(string text, FontX3D font, PointD3D pointD3D) { return FontManager3D.Instance.MeasureString(text, font); }
/// <summary> /// Measures the item, i.e. returns the size of the item. /// </summary> /// <param name="g">Graphics context.</param> /// <param name="font">The font that is used to draw the item.</param> /// <param name="strfmt">String format used to draw the item.</param> /// <param name="mtick">The item to draw.</param> /// <param name="morg">The location the item will be drawn.</param> /// <returns>The size of the item if it would be drawn.</returns> public virtual VectorD3D MeasureItem(IGraphicsContext3D g, FontX3D font, Altaxo.Data.AltaxoVariant mtick, PointD3D morg) { string text = _prefix + FormatItem(mtick) + _suffix; return g.MeasureString(text, font, morg); }
public virtual void DrawString(string text, FontX3D font, IMaterial brush, PointD3D point) { var txt = new SolidText(text, font); /* * VectorD3D stringSize = new VectorD3D(0, 0, font.Depth); * * if (stringAlignment.AlignmentX != Alignment.Near || stringAlignment.AlignmentY != Alignment.Near) * stringSize = FontManager3D.Instance.MeasureString(text, font); * * switch (stringAlignment.AlignmentX) * { * case Alignment.Near: * break; * * case Alignment.Center: * point = point.WithXPlus(-0.5 * stringSize.X); * break; * * case Alignment.Far: * point = point.WithXPlus(-stringSize.X); * break; * * default: * break; * } * * switch (stringAlignment.AlignmentY) * { * case Alignment.Near: * break; * * case Alignment.Center: * point = point.WithYPlus(-0.5 * stringSize.Y); * break; * * case Alignment.Far: * point = point.WithYPlus(-stringSize.Y); * break; * * default: * break; * } * * switch (stringAlignment.AlignmentZ) * { * case Alignment.Near: * break; * * case Alignment.Center: * point = point.WithZPlus(-0.5 * stringSize.Z); * break; * * case Alignment.Far: * point = point.WithZPlus(-stringSize.Z); * break; * * default: * break; * } */ var buffers = GetPositionNormalIndexedTriangleBuffer(brush); var offset = buffers.IndexedTriangleBuffer.VertexCount; if (null != buffers.PositionNormalIndexedTriangleBuffer) { var buf = buffers.PositionNormalIndexedTriangleBuffer; txt.AddWithNormals( FontManager3D.Instance.GetCharacterGeometry, (position, normal) => buf.AddTriangleVertex(position.X + point.X, position.Y + point.Y, position.Z + point.Z, normal.X, normal.Y, normal.Z), (i0, i1, i2) => buf.AddTriangleIndices(i0, i1, i2), ref offset); } else if (null != buffers.PositionNormalColorIndexedTriangleBuffer) { var buf = buffers.PositionNormalColorIndexedTriangleBuffer; var color = brush.Color.Color; var r = color.ScR; var g = color.ScG; var b = color.ScB; var a = color.ScA; txt.AddWithNormals( FontManager3D.Instance.GetCharacterGeometry, (position, normal) => buf.AddTriangleVertex(position.X + point.X, position.Y + point.Y, position.Z + point.Z, normal.X, normal.Y, normal.Z, r, g, b, a), (i0, i1, i2) => buf.AddTriangleIndices(i0, i1, i2), ref offset); } else if (null != buffers.PositionNormalUVIndexedTriangleBuffer) { throw new NotImplementedException("Texture on a text is not supported yet"); } else { throw new NotImplementedException("Unexpected type of buffer: " + buffers.IndexedTriangleBuffer.GetType().ToString()); } }
public AxisLabelStyle(CSAxisSide? labelSide, Altaxo.Main.Properties.IReadOnlyPropertyBag context) { if (null == context) context = PropertyExtensions.GetPropertyContextOfProject(); _labelSide = labelSide; _font = GraphDocument.GetDefaultFont(context); var foreColor = GraphDocument.GetDefaultForeColor(context); _brush = Materials.GetSolidMaterial(foreColor); _automaticRotationShift = true; _rotationX = 90; _suppressedLabels = new SuppressedTicks() { ParentObject = this }; _labelFormatting = new LabelFormatting.NumericLabelFormattingAuto() { ParentObject = this }; }
public MeasuredLabelItem(IGraphicsContext3D g, FontX3D font, string itemtext) { _text = itemtext; _font = font; _size = g.MeasureString(_text, _font, new PointD3D(0, 0, 0)); }
public override IMeasuredLabelItem[] GetMeasuredItems(IGraphicsContext3D g, FontX3D font, AltaxoVariant[] items) { var litems = new MeasuredLabelItem[items.Length]; var localfont1 = font; var localfont2 = font.WithSize(font.Size * 2 / 3); string[] firstp = new string[items.Length]; string[] middel = new string[items.Length]; string[] expos = new string[items.Length]; double[] mants = new double[items.Length]; double maxexposize = 0; int firstpartmin = int.MaxValue; int firstpartmax = int.MinValue; for (int i = 0; i < items.Length; ++i) { string firstpart, exponent; if (items[i].IsType(Altaxo.Data.AltaxoVariant.Content.VDouble)) { SplitInFirstPartAndExponent(items[i], out firstpart, out mants[i], out middel[i], out exponent); if (exponent.Length > 0) { firstpartmin = Math.Min(firstpartmin, firstpart.Length); firstpartmax = Math.Max(firstpartmax, firstpart.Length); } } else { firstpart = items[i].ToString(); middel[i] = string.Empty; exponent = string.Empty; } firstp[i] = firstpart; expos[i] = exponent; maxexposize = Math.Max(maxexposize, g.MeasureString(exponent, localfont2, PointD3D.Empty).X); } if (firstpartmax > 0 && firstpartmax > firstpartmin) // then we must use special measures to equilibrate the mantissa { firstp = NumericLabelFormattingAuto.FormatItems(mants); } for (int i = 0; i < items.Length; ++i) { string mid = string.Empty; if (!string.IsNullOrEmpty(expos[i])) { if (string.IsNullOrEmpty(firstp[i])) { mid = "10"; } else { mid = "\u00D710"; } } litems[i] = new MeasuredLabelItem(g, localfont1, localfont2, _prefix + firstp[i] + mid, expos[i], _suffix, maxexposize); } return(litems); }
public TextGraphic(PointD3D graphicPosition, string text, FontX3D textFont, NamedColor textColor) : base(new ItemLocationDirectAutoSize()) { this.SetPosition(graphicPosition, Main.EventFiring.Suppressed); this.Font = textFont; this.Text = text; this.Color = textColor; }
public virtual void DrawString(string text, FontX3D font, IMaterial brush, PointD3D point, Alignment alignmentX, Alignment alignmentY, Alignment alignmentZ) { var stringSize = new VectorD3D(0, 0, font.Depth); // depth is already known, for this we don't need to call MeasureString if (alignmentX != Alignment.Near || alignmentY != Alignment.Near) { stringSize = FontManager3D.Instance.MeasureString(text, font); } switch (alignmentX) { case Alignment.Near: break; case Alignment.Center: point = point.WithXPlus(-0.5 * stringSize.X); break; case Alignment.Far: point = point.WithXPlus(-stringSize.X); break; default: break; } switch (alignmentY) { case Alignment.Near: break; case Alignment.Center: point = point.WithYPlus(-0.5 * stringSize.Y); break; case Alignment.Far: point = point.WithYPlus(-stringSize.Y); break; default: break; } switch (alignmentZ) { case Alignment.Near: break; case Alignment.Center: point = point.WithZPlus(-0.5 * stringSize.Z); break; case Alignment.Far: point = point.WithZPlus(-stringSize.Z); break; default: break; } DrawString(text, font, brush, point); }
public void SetRoutedProperty(IRoutedSetterProperty property) { switch (property.Name) { case "FontSize": { var prop = (RoutedSetterProperty<double>)property; this.Font = _font.WithSize(prop.Value); EhSelfChanged(EventArgs.Empty); } break; case "FontFamily": { var prop = (RoutedSetterProperty<string>)property; try { var newFont = _font.WithFamily(prop.Value); _font = newFont; _isStructureInSync = false; EhSelfChanged(EventArgs.Empty); } catch (Exception) { } } break; } }
public LabelPlotStyle(Altaxo.Data.IReadableColumn labelColumn, Altaxo.Main.Properties.IReadOnlyPropertyBag context) { this._font = GraphDocument.GetDefaultFont(context); this._fontSizeOffset = _font.Size; var color = GraphDocument.GetDefaultPlotColor(context); this._independentColor = false; this._material = new MaterialWithUniformColor(color); this._backgroundColorLinkage = ColorLinkage.Independent; this.LabelColumnProxy = Altaxo.Data.ReadableColumnProxyBase.FromColumn(labelColumn); }
/// <summary> /// Merges the providedstyle into the present style. Example: if the present style is Bold, and the style parameter is Italic, then the merged style is 'Bold Italic'. /// </summary> /// <param name="style">The style to merge with the present style.</param> public void MergeFontStyle(FontXStyle style) { var newStyle = FontId.Style | style; FontId = FontId.WithStyle(newStyle); }
public void Paint(IGraphicsContext3D g, IPlotArea layer, Processed3DPlotData pdata, Processed3DPlotData prevItemData, Processed3DPlotData nextItemData) { if (this._labelColumnProxy.Document == null) return; if (null != _attachedPlane) _attachedPlane = layer.UpdateCSPlaneID(_attachedPlane); PlotRangeList rangeList = pdata.RangeList; var ptArray = pdata.PlotPointsInAbsoluteLayerCoordinates; Altaxo.Data.IReadableColumn labelColumn = this._labelColumnProxy.Document; bool isUsingVariableColorForLabelText = null != _cachedColorForIndexFunction && IsColorReceiver; bool isUsingVariableColorForLabelBackground = null != _cachedColorForIndexFunction && (null != _backgroundStyle && _backgroundStyle.SupportsUserDefinedMaterial && (_backgroundColorLinkage == ColorLinkage.Dependent || _backgroundColorLinkage == ColorLinkage.PreserveAlpha)); bool isUsingVariableColor = isUsingVariableColorForLabelText || isUsingVariableColorForLabelBackground; IMaterial clonedTextBrush = _material; IMaterial clonedBackBrush = null; if (isUsingVariableColorForLabelBackground) clonedBackBrush = _backgroundStyle.Material; // save the graphics stat since we have to translate the origin var gs = g.SaveGraphicsState(); double xpos = 0, ypos = 0, zpos = 0; double xpre, ypre, zpre; double xdiff, ydiff, zdiff; bool isFormatStringContainingBraces = _labelFormatString?.IndexOf('{') >= 0; var culture = System.Threading.Thread.CurrentThread.CurrentCulture; bool mustUseLogicalCoordinates = null != this._attachedPlane || 0 != _cachedLogicalShiftX || 0 != _cachedLogicalShiftY || 0 != _cachedLogicalShiftZ; for (int r = 0; r < rangeList.Count; r++) { int lower = rangeList[r].LowerBound; int upper = rangeList[r].UpperBound; int offset = rangeList[r].OffsetToOriginal; for (int j = lower; j < upper; j += _skipFrequency) { string label; if (string.IsNullOrEmpty(_labelFormatString)) { label = labelColumn[j + offset].ToString(); } else if (!isFormatStringContainingBraces) { label = labelColumn[j + offset].ToString(_labelFormatString, culture); } else { // the label format string can contain {0} for the label column item, {1} for the row index, {2} .. {4} for the x, y and z component of the data point label = string.Format(_labelFormatString, labelColumn[j + offset], j + offset, pdata.GetPhysical(0, j + offset), pdata.GetPhysical(1, j + offset), pdata.GetPhysical(2, j + offset)); } if (string.IsNullOrEmpty(label)) continue; double localSymbolSize = _symbolSize; if (null != _cachedSymbolSizeForIndexFunction) { localSymbolSize = _cachedSymbolSizeForIndexFunction(j + offset); } double localFontSize = _fontSizeOffset + _fontSizeFactor * localSymbolSize; if (!(localFontSize > 0)) continue; _font = _font.WithSize(localFontSize); // Start of preparation of brushes, if a variable color is used if (isUsingVariableColor) { var c = _cachedColorForIndexFunction(j + offset); if (isUsingVariableColorForLabelText) { clonedTextBrush = clonedTextBrush.WithColor(new NamedColor(AxoColor.FromArgb(c.A, c.R, c.G, c.B), "e")); } if (isUsingVariableColorForLabelBackground) { if (_backgroundColorLinkage == ColorLinkage.PreserveAlpha) clonedBackBrush = clonedBackBrush.WithColor(new NamedColor(AxoColor.FromArgb(clonedBackBrush.Color.Color.A, c.R, c.G, c.B), "e")); else clonedBackBrush = clonedBackBrush.WithColor(new NamedColor(AxoColor.FromArgb(c.A, c.R, c.G, c.B), "e")); } } // end of preparation of brushes for variable colors if (mustUseLogicalCoordinates) // we must use logical coordinates because either there is a shift of logical coordinates, or an attached plane { Logical3D r3d = layer.GetLogical3D(pdata, j + offset); r3d.RX += _cachedLogicalShiftX; r3d.RY += _cachedLogicalShiftY; r3d.RZ += _cachedLogicalShiftZ; if (null != this._attachedPlane) { var pp = layer.CoordinateSystem.GetPointOnPlane(this._attachedPlane, r3d); xpre = pp.X; ypre = pp.Y; zpre = pp.Z; } else { PointD3D pt; layer.CoordinateSystem.LogicalToLayerCoordinates(r3d, out pt); xpre = pt.X; ypre = pt.Y; zpre = pt.Z; } } else // no shifting, thus we can use layer coordinates { xpre = ptArray[j].X; ypre = ptArray[j].Y; zpre = ptArray[j].Z; } xdiff = xpre - xpos; ydiff = ypre - ypos; zdiff = zpre - zpos; xpos = xpre; ypos = ypre; zpos = zpre; g.TranslateTransform(xdiff, ydiff, zdiff); g.RotateTransform(_rotationX, _rotationY, _rotationZ); this.Paint(g, label, localSymbolSize, clonedTextBrush, clonedBackBrush); g.RotateTransform(-_rotationX, -_rotationY, -_rotationZ); } // end for } g.RestoreGraphicsState(gs); // Restore the graphics state }
public void SetFont(FontX3D font) { FontId = font; }
/// <summary> /// Measures the item, i.e. returns the size of the item. /// </summary> /// <param name="g">Graphics context.</param> /// <param name="font">The font that is used to draw the item.</param> /// <param name="mtick">The item to draw.</param> /// <param name="morg">The location the item will be drawn.</param> /// <returns>The size of the item if it would be drawn.</returns> public virtual VectorD3D MeasureItem(IGraphicsContext3D g, FontX3D font, Altaxo.Data.AltaxoVariant mtick, PointD3D morg) { string text = _prefix + FormatItem(mtick) + _suffix; return(g.MeasureString(text, font, morg)); }
public bool CopyFrom(object obj, bool copyWithDataReferences) { if (object.ReferenceEquals(this, obj)) return true; var from = obj as LabelPlotStyle; if (null == from) return false; using (var suspendToken = SuspendGetToken()) { this._attachedPlane = from._attachedPlane; this._independentSkipFrequency = from._independentSkipFrequency; this._skipFrequency = from._skipFrequency; this._independentOnShiftingGroupStyles = from._independentOnShiftingGroupStyles; this._labelFormatString = from._labelFormatString; this._independentSymbolSize = from._independentSymbolSize; this._symbolSize = from._symbolSize; this._fontSizeOffset = from._fontSizeOffset; this._fontSizeFactor = from._fontSizeFactor; this._font = from._font; this._material = from._material; this._independentColor = from._independentColor; this._alignmentX = from._alignmentX; this._alignmentY = from._alignmentY; this._alignmentZ = from._alignmentZ; this._rotationX = from._rotationX; this._rotationY = from._rotationY; this._rotationZ = from._rotationZ; this._offsetX_Points = from._offsetX_Points; this._offsetX_EmUnits = from._offsetX_EmUnits; this._offsetX_SymbolSizeUnits = from._offsetX_SymbolSizeUnits; this._offsetY_Points = from._offsetY_Points; this._offsetY_EmUnits = from._offsetY_EmUnits; this._offsetY_SymbolSizeUnits = from._offsetY_SymbolSizeUnits; this._offsetZ_Points = from._offsetZ_Points; this._offsetZ_EmUnits = from._offsetZ_EmUnits; this._offsetZ_SymbolSizeUnits = from._offsetZ_SymbolSizeUnits; this._backgroundColorLinkage = from._backgroundColorLinkage; ChildCopyToMember(ref _backgroundStyle, from._backgroundStyle); this._cachedLogicalShiftX = from._cachedLogicalShiftX; this._cachedLogicalShiftY = from._cachedLogicalShiftY; this._cachedLogicalShiftZ = from._cachedLogicalShiftZ; if (copyWithDataReferences) this.LabelColumnProxy = (Altaxo.Data.IReadableColumnProxy)from._labelColumnProxy.Clone(); EhSelfChanged(EventArgs.Empty); suspendToken.Resume(); } return true; }
/// <summary> /// Measures a couple of items and prepares them for being drawn. /// </summary> /// <param name="g">Graphics context.</param> /// <param name="font">Font used.</param> /// <param name="strfmt">String format used.</param> /// <param name="items">Array of items to be drawn.</param> /// <returns>An array of <see cref="IMeasuredLabelItem" /> that can be used to determine the size of each item and to draw it.</returns> public virtual IMeasuredLabelItem[] GetMeasuredItems(IGraphicsContext3D g, FontX3D font, AltaxoVariant[] items) { string[] titems = FormatItems(items); if (!string.IsNullOrEmpty(_prefix) || !string.IsNullOrEmpty(_suffix)) { for (int i = 0; i < titems.Length; ++i) titems[i] = _prefix + titems[i] + _suffix; } MeasuredLabelItem[] litems = new MeasuredLabelItem[titems.Length]; FontX3D localfont = font; for (int i = 0; i < titems.Length; ++i) { litems[i] = new MeasuredLabelItem(g, localfont, titems[i]); } return litems; }
/// <summary>Measures the string with the appropriate generic typographic format.</summary> /// <param name="text">The text to measure.</param> /// <param name="font">The font used.</param> /// <returns>Width and height of the text packed into a <see cref="VectorD3D"/> structure.</returns> public static VectorD3D MeasureString(string text, FontX3D font) { return FontManager3D.Instance.MeasureString(text, font); }
public virtual VectorD3D MeasureString(string text, FontX3D font, PointD3D pointD3D) { return(FontManager3D.Instance.MeasureString(text, font)); }