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 == null ? null : from._textBrush.Clone(); if (null != _textBrush) { _textBrush.ParentObject = this; } _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); }
public TextGraphic(PointD2D graphicPosition, string text, FontX textFont, NamedColor textColor, double Rotation) : this(graphicPosition, text, textFont, textColor) { this.Rotation = Rotation; }
public override void DrawItem(Graphics g, BrushX brush, FontX font, StringFormat strfmt, Altaxo.Data.AltaxoVariant item, PointF morg) { SplitInFirstPartAndExponent(item, out var firstpart, out var mant, out var middelpart, out var exponent); var gdiFont = GdiFontManager.ToGdi(font); SizeF size1 = g.MeasureString(_prefix + firstpart + middelpart, gdiFont, morg, strfmt); g.DrawString(_prefix + firstpart + middelpart, gdiFont, brush, morg, strfmt); var orginalY = morg.Y; morg.X += size1.Width; morg.Y += size1.Height / 3; FontX font2 = font.WithSize(font.Size * 2 / 3.0); var gdiFont2 = GdiFontManager.ToGdi(font2); g.DrawString(exponent, gdiFont2, brush, morg); if (!string.IsNullOrEmpty(_suffix)) { morg.X += g.MeasureString(exponent, gdiFont2, morg, strfmt).Width; morg.Y = orginalY; } if (!string.IsNullOrEmpty(_suffix)) { g.DrawString(_suffix, gdiFont, brush, morg, strfmt); } }
/// <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 override IMeasuredLabelItem[] GetMeasuredItems(Graphics g, FontX font, System.Drawing.StringFormat strfmt, 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]; FontX localfont = font; var localstrfmt = (StringFormat)strfmt.Clone(); StringAlignment horizontalAlignment = localstrfmt.Alignment; StringAlignment verticalAlignment = localstrfmt.LineAlignment; localstrfmt.Alignment = StringAlignment.Near; localstrfmt.LineAlignment = StringAlignment.Near; for (int i = 0; i < titems.Length; ++i) { litems[i] = new MeasuredLabelItem(g, localfont, localstrfmt, titems[i], _relativeLineSpacing, horizontalAlignment, verticalAlignment, _textBlockAlignment); } return(litems); }
public MeasuredLabelItem(Graphics g, FontX font, StringFormat strfmt, string itemtext) { _text = itemtext; _font = font; _strfmt = strfmt; _size = g.MeasureString(_text, GdiFontManager.ToGdi(_font), new PointF(0, 0), strfmt); }
public TextGraphic(double posX, double posY, string text, FontX textFont, NamedColor textColor, double Rotation) : this(new PointD2D(posX, posY), text, textFont, textColor, Rotation) { }
public AxsSequence(IStreamReader reader) : base(reader) { //AXS = [IFmtRecord] [Tick] [FontX] *4(AxisLine LineFormat) [AreaFormat] [GELFRAME] *4SHAPEPROPS [TextPropsStream *ContinueFrt12] //[IFmtRecord] if (BiffRecord.GetNextRecordType(reader) == RecordType.IFmtRecord) { this.IFmtRecord = (IFmtRecord)BiffRecord.ReadRecord(reader); } //[Tick] if (BiffRecord.GetNextRecordType(reader) == RecordType.Tick) { this.Tick = (Tick)BiffRecord.ReadRecord(reader); } //[FontX] if (BiffRecord.GetNextRecordType(reader) == RecordType.FontX) { this.FontX = (FontX)BiffRecord.ReadRecord(reader); } //*4(AxisLine LineFormat) this.AxisLineFormatGroups = new List <AxisLineFormatGroup>(); while (BiffRecord.GetNextRecordType(reader) == RecordType.AxisLine) { this.AxisLineFormatGroups.Add(new AxisLineFormatGroup(reader)); } //[AreaFormat] if (BiffRecord.GetNextRecordType(reader) == RecordType.AreaFormat) { this.AreaFormat = (AreaFormat)BiffRecord.ReadRecord(reader); } //[GELFRAME] if (BiffRecord.GetNextRecordType(reader) == RecordType.GelFrame) { this.GelFrame = (GelFrame)BiffRecord.ReadRecord(reader); } //*4SHAPEPROPS this.ShapePropsSequences = new List <ShapePropsSequence>(); while (BiffRecord.GetNextRecordType(reader) == RecordType.ShapePropsStream) { this.ShapePropsSequences.Add(new ShapePropsSequence(reader)); } //[TextPropsStream *ContinueFrt12] if (BiffRecord.GetNextRecordType(reader) == RecordType.TextPropsStream) { this.TextPropsStream = (TextPropsStream)BiffRecord.ReadRecord(reader); while (BiffRecord.GetNextRecordType(reader) == RecordType.ContinueFrt12) { this.ContinueFrt12s.Add((ContinueFrt12)BiffRecord.ReadRecord(reader)); } } }
private void EhFontFamily_SelectionChangeCommitted(object sender, EventArgs e) { if (FontX != null) { FontX = FontX.WithFamily(_cbFontFamily.SelectedFontFamilyName); OnSelectedFontChanged(); } }
private void EhFontSize_SelectionChangeCommitted(object sender, System.Windows.DependencyPropertyChangedEventArgs e) { if (FontX != null) { FontX = FontX.WithSize(_cbFontSize.SelectedQuantityAsValueInPoints); OnSelectedFontChanged(); } }
private void EhFontStyle_SelectionChangeCommitted(object sender, EventArgs e) { if (FontX != null) { FontX = FontX.WithStyle(_cbFontStyle.SelectedFontStyle); OnSelectedFontChanged(); } }
public FontInfo GetFontInfo(Graphics g, FontX id) { if (!_fontInfoDictionary.TryGetValue(id, out var result)) { result = FontInfo.Create(g, id); _fontInfoDictionary.Add(id, result); } return result; }
public TextGraphic(PointD2D graphicPosition, string text, FontX textFont, NamedColor textColor) : base(new ItemLocationDirectAutoSize()) { SetPosition(graphicPosition, Main.EventFiring.Suppressed); Font = textFont; Text = text; Color = textColor; }
public FontInfo GetFontInfo(Graphics g, FontX id) { FontInfo result; if (!_fontInfoDictionary.TryGetValue(id, out result)) { result = FontInfo.Create(g, id); _fontInfoDictionary.Add(id, result); } return result; }
/// <summary> /// Gets the family name from a <see cref="FontX"/> instance. If this font family name does not exist, a generic sans serif font family name is returned instead. /// </summary> /// <param name="font">The font.</param> /// <returns>Font family name, either the original name from the provided font, or if that is not valid, a valid generic font family name.</returns> public static string GetValidFontFamilyName(FontX font) { if (_instance._dictWin32FamilyNameToGdiFontFamilyAndPresence.ContainsKey(font.FontFamilyName)) { return(font.FontFamilyName); } else { return(GenericSansSerifFontFamilyName); } }
public override System.Drawing.SizeF MeasureItem(System.Drawing.Graphics g, FontX font, System.Drawing.StringFormat strfmt, Altaxo.Data.AltaxoVariant mtick, System.Drawing.PointF morg) { SplitInFirstPartAndExponent(mtick, out var firstpart, out var mant, out var middelpart, out var exponent); var gdiFont = GdiFontManager.ToGdi(font); SizeF size1 = g.MeasureString(_prefix + firstpart + middelpart, gdiFont, new PointF(0, 0), strfmt); SizeF size2 = g.MeasureString(exponent, gdiFont, new PointF(size1.Width, 0), strfmt); SizeF size3 = g.MeasureString(_suffix, gdiFont, new PointF(0, 0), strfmt); return(new SizeF(size1.Width + size2.Width + size3.Width, size1.Height)); }
private static void InternalGetInformation(Graphics g, FontInfo result, FontX font) { // get some properties of the font var gdiFont = GdiFontManager.ToGdi(font); result.Size = gdiFont.Size; result.cyLineSpace = gdiFont.GetHeight(g); // space between two lines int iCellSpace = gdiFont.FontFamily.GetLineSpacing(gdiFont.Style); int iCellAscent = gdiFont.FontFamily.GetCellAscent(gdiFont.Style); int iCellDescent = gdiFont.FontFamily.GetCellDescent(gdiFont.Style); result.cyAscent = result.cyLineSpace * iCellAscent / iCellSpace; result.cyDescent = result.cyLineSpace * iCellDescent / iCellSpace; }
/// <summary> /// Retrieves a Wpf <see cref="System.Windows.Media.Typeface"/> from a given <see cref="FontX"/> instance. Since a <see cref="System.Windows.Media.Typeface"/> doesn't contain /// information about the font size, you are responsible for drawing the font with the intended size. You can use <see cref="FontX.Size"/>, but be aware that the size is returned in units /// of points (1/72 inch), but Wpf expects units of 1/96 inch. /// </summary> /// <param name="fontX">The font X to convert to a Wpf typeface.</param> /// <returns>The Wpf typeface that corresponds to the provided <see cref="FontX"/> instance.</returns> protected virtual Typeface InternalToWpf(FontX fontX) { string fontID = fontX.FontFamilyName + ", " + fontX.Style.ToString(); if (!_dictDescriptionStringToWpfTypeface.TryGetValue(fontID, out var result)) { result = _dictDescriptionStringToWpfTypeface.AddOrUpdate(fontID, x => CreateNewTypeface(fontX), (x, y) => y); } return(result); }
public MeasuredLabelItem(Graphics g, FontX font1, FontX font2, StringFormat strfmt, string firstpart, string exponent, string lastpart, float maxexposize) { _firstpart = firstpart; _exponent = exponent; _lastpart = lastpart; _font1 = font1; _font2 = font2; _strfmt = strfmt; _size1 = g.MeasureString(_firstpart, GdiFontManager.ToGdi(_font1), new PointF(0, 0), strfmt); _size2 = g.MeasureString(_exponent, GdiFontManager.ToGdi(_font2), new PointF(_size1.Width, 0), strfmt); _size3 = g.MeasureString(_lastpart, GdiFontManager.ToGdi(_font1), new PointF(0, 0), strfmt); _rightPadding = maxexposize - _size2.Width; }
/// <summary> /// Retrieves the Gdi+ font instance that the provided <see cref="FontX"/> argument is describing. /// </summary> /// <param name="fontX">The fontX instance.</param> /// <returns>The Gdi+ font instance that corresponds with the argument. If the font family of the fontX argument is not found, a default font (Microsoft Sans Serif) is returned.</returns> protected virtual Font InternalToGdi(FontX fontX) { string fontID = fontX.InvariantDescriptionString; if (!_dictDescriptionStringToGdiFont.TryGetValue(fontID, out var result)) { result = _dictDescriptionStringToGdiFont.AddOrUpdate(fontID, x => InternalGetGdiFontFromInvariantString(x), (x, y) => y); } return(result); }
public TextGraphic(Altaxo.Main.Properties.IReadOnlyPropertyBag context) : base(new ItemLocationDirectAutoSize()) { if (null == context) { context = PropertyExtensions.GetPropertyContextOfProject(); } _font = context.GetValue(GraphDocument.PropertyKeyDefaultFont); _textBrush = new BrushX(context.GetValue(GraphDocument.PropertyKeyDefaultForeColor)) { ParentObject = this }; }
public ColumnStyle(ColumnStyle s) { _columnStyleType = s._columnStyleType; _columnSize = s._columnSize; _isCellPenCustom = s._isCellPenCustom; ChildCopyToMember(ref _cellPen, s._cellPen); _textFormat = (StringFormat)s._textFormat.Clone(); _textFont = s._textFont; _isTextBrushCustom = s._isTextBrushCustom; ChildCopyToMember(ref _textBrush, s._textBrush); _isBackgroundBrushCustom = s._isBackgroundBrushCustom; ChildCopyToMember(ref _backgroundBrush, s._backgroundBrush); }
public override bool CopyFrom(object obj) { var isCopied = base.CopyFrom(obj); if (isCopied && !object.ReferenceEquals(this, obj)) { var from = obj as SimpleTextGraphic; if (null != from) { _font = from._font; _text = from._text; _color = from._color; } } return(isCopied); }
public CharacterGeometry GetCharacterGeometry(FontX font, char textChar) { var typefaceName = font.InvariantDescriptionStringWithoutSizeInformation; if (!_cachedCharacterOutlines.TryGetValue(typefaceName, out var cachedCharacters)) { cachedCharacters = new Dictionary <char, CharacterGeometry>(); _cachedCharacterOutlines.Add(typefaceName, cachedCharacters); } if (!cachedCharacters.TryGetValue(textChar, out var cachedChar)) { cachedChar = InternalGetCharacterGeometryForCaching(textChar, font); cachedCharacters.Add(textChar, cachedChar); } return(cachedChar); }
public MeasuredLabelItem(Graphics g, FontX font, StringFormat strfmt, string itemtext, double lineSpacing, StringAlignment horizontalAlignment, StringAlignment verticalAlignment, StringAlignment textBlockAligment) { _text = itemtext.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); _stringSize = new PointD2D[_text.Length]; _font = font; _horizontalAlignment = horizontalAlignment; _verticalAlignment = verticalAlignment; _textBlockAligment = textBlockAligment; _strfmt = strfmt; _lineSpacing = lineSpacing; _size = SizeF.Empty; var bounds = RectangleD2D.Empty; var position = new PointD2D(); for (int i = 0; i < _text.Length; ++i) { _stringSize[i] = g.MeasureString(_text[i], GdiFontManager.ToGdi(_font), new PointF(0, 0), strfmt); bounds.ExpandToInclude(new RectangleD2D(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="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(Graphics g, FontX font, System.Drawing.StringFormat strfmt, 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]; FontX localfont = font; var localstrfmt = (StringFormat)strfmt.Clone(); for (int i = 0; i < titems.Length; ++i) { litems[i] = new MeasuredLabelItem(g, localfont, localstrfmt, titems[i]); } return(litems); }
public AttachedLabelSequence(IStreamReader reader) : base(reader) { //ATTACHEDLABEL = Text Begin Pos [FontX] [AlRuns] AI [FRAME] [ObjectLink] [DataLabExtContents] [CrtLayout12] [TEXTPROPS] [CRTMLFRT] End //Text this.Text = (Text)BiffRecord.ReadRecord(reader); //Begin this.Begin = (Begin)BiffRecord.ReadRecord(reader); //Pos this.Pos = (Pos)BiffRecord.ReadRecord(reader); //[FontX] if (BiffRecord.GetNextRecordType(reader) == RecordType.FontX) { this.FontX = (FontX)BiffRecord.ReadRecord(reader); } //[AlRuns] if (BiffRecord.GetNextRecordType(reader) == RecordType.AlRuns) { this.AlRuns = (AlRuns)BiffRecord.ReadRecord(reader); } //AI this.AiSequence = new AiSequence(reader); //[FRAME] if (BiffRecord.GetNextRecordType(reader) == RecordType.Frame) { this.FrameSequence = new FrameSequence(reader); } //[ObjectLink] if (BiffRecord.GetNextRecordType(reader) == RecordType.ObjectLink) { this.ObjectLink = (ObjectLink)BiffRecord.ReadRecord(reader); } //[DataLabExtContents] if (BiffRecord.GetNextRecordType(reader) == RecordType.DataLabExtContents) { this.DataLabExtContents = (DataLabExtContents)BiffRecord.ReadRecord(reader); } //[CrtLayout12] if (BiffRecord.GetNextRecordType(reader) == RecordType.CrtLayout12) { this.CrtLayout12 = (CrtLayout12)BiffRecord.ReadRecord(reader); } //[TEXTPROPS] if (BiffRecord.GetNextRecordType(reader) == RecordType.RichTextStream || BiffRecord.GetNextRecordType(reader) == RecordType.TextPropsStream) { this.TextPropsSequence = new TextPropsSequence(reader); } //[CRTMLFRT] if (BiffRecord.GetNextRecordType(reader) == RecordType.CrtMlFrt) { this.CrtMlfrtSequence = new CrtMlfrtSequence(reader); } //End this.End = (End)BiffRecord.ReadRecord(reader); }
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._brush = new BrushX(color) { ParentObject = this }; this._backgroundColorLinkage = ColorLinkage.Independent; this.LabelColumnProxy = Altaxo.Data.ReadableColumnProxyBase.FromColumn(labelColumn); this._cachedStringFormat = new StringFormat(StringFormatFlags.NoWrap); }
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._ignoreMissingDataPoints = from._ignoreMissingDataPoints; 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; ChildCopyToMember(ref _brush, from._brush); this._independentColor = from._independentColor; this._alignmentX = from._alignmentX; this._alignmentY = from._alignmentY; this._rotation = from._rotation; 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._backgroundColorLinkage = from._backgroundColorLinkage; ChildCopyToMember(ref _backgroundStyle, from._backgroundStyle); this._cachedLogicalShiftX = from._cachedLogicalShiftX; this._cachedLogicalShiftY = from._cachedLogicalShiftY; this._cachedStringFormat = (System.Drawing.StringFormat)from._cachedStringFormat.Clone(); if (copyWithDataReferences) this.LabelColumnProxy = (Altaxo.Data.IReadableColumnProxy)from._labelColumnProxy.Clone(); EhSelfChanged(EventArgs.Empty); suspendToken.Resume(); } return true; }
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 == null ? null : (BrushX)from._textBrush.Clone(); if (null != _textBrush) _textBrush.ParentObject = this; 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 TextGraphic(Altaxo.Main.Properties.IReadOnlyPropertyBag context) : base(new ItemLocationDirectAutoSize()) { if (null == context) context = PropertyExtensions.GetPropertyContextOfProject(); _font = context.GetValue(GraphDocument.PropertyKeyDefaultFont); _textBrush = new BrushX(context.GetValue(GraphDocument.PropertyKeyDefaultForeColor)) { ParentObject = this }; }
public StyleContext(FontX font, Brush brush) { FontId = font; this.brush = brush; }
public void SetFont(FontX font) { FontId = font; }
public AxisLabelStyle(Altaxo.Main.Properties.IReadOnlyPropertyBag context) { if (null == context) context = PropertyExtensions.GetPropertyContextOfProject(); _font = context.GetValue(GraphDocument.PropertyKeyDefaultFont); var foreColor = context.GetValue(GraphDocument.PropertyKeyDefaultForeColor); _brush = new BrushX(foreColor) { ParentObject = this }; _automaticRotationShift = true; _suppressedLabels = new SuppressedTicks() { ParentObject = this }; _labelFormatting = new Gdi.LabelFormatting.NumericLabelFormattingAuto() { ParentObject = this }; SetStringFormat(); }
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; CopyHelper.Copy(ref _stringFormat, from._stringFormat); _horizontalAlignment = from._horizontalAlignment; _verticalAlignment = from._verticalAlignment; ChildCopyToMember(ref _brush, from._brush); _automaticRotationShift = from._automaticRotationShift; _xOffset = from._xOffset; _yOffset = from._yOffset; _rotation = from._rotation; 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; }
private RawCharacterOutline InternalGetCharacterOutlineForCaching(char textChar, FontX font) { var glyphTypeface = font.InvariantDescriptionStringWithoutSizeInformation; var rawOutline = GetRawCharacterOutline(textChar, font, FontSizeForCaching); List<List<ClipperLib.IntPoint>> clipperPolygonsInput = new List<List<ClipperLib.IntPoint>>(); var sharpPoints = new HashSet<ClipperLib.IntPoint>(); var allPoints = new HashSet<ClipperLib.IntPoint>(); // allPoints to determine whether after the simplification new points were added foreach (var polygon in rawOutline.Outline) { foreach (var p in polygon.SharpPoints) { sharpPoints.Add(new ClipperLib.IntPoint(p.X * 65536, p.Y * 65536)); } var clipperPolygon = new List<ClipperLib.IntPoint>(polygon.Points.Select((x) => new ClipperLib.IntPoint(x.X * 65536, x.Y * 65536))); clipperPolygonsInput.Add(clipperPolygon); foreach (var clipperPoint in clipperPolygon) allPoints.Add(clipperPoint); } //clipperPolygons = ClipperLib.Clipper.SimplifyPolygons(clipperPolygons, ClipperLib.PolyFillType.pftEvenOdd); var clipperPolygons = new ClipperLib.PolyTree(); ClipperLib.Clipper clipper = new ClipperLib.Clipper(); clipper.StrictlySimple = true; clipper.AddPaths(clipperPolygonsInput, ClipperLib.PolyType.ptSubject, true); clipper.Execute(ClipperLib.ClipType.ctUnion, clipperPolygons, ClipperLib.PolyFillType.pftNonZero, ClipperLib.PolyFillType.pftNegative); var polygons = new List<PolygonClosedD2D>(); var dictClipperNodeToNode = new Dictionary<ClipperLib.PolyNode, PolygonClosedD2D>(); // helper dictionary ClipperPolyTreeToPolygonListRecursively(clipperPolygons, sharpPoints, allPoints, polygons, dictClipperNodeToNode); var result = rawOutline; result.Outline = polygons; return result; }
public CharacterGeometry GetCharacterGeometry(FontX font, char textChar) { var typefaceName = font.InvariantDescriptionStringWithoutSizeInformation; Dictionary<char, CharacterGeometry> cachedCharacters; if (!_cachedCharacterOutlines.TryGetValue(typefaceName, out cachedCharacters)) { cachedCharacters = new Dictionary<char, CharacterGeometry>(); _cachedCharacterOutlines.Add(typefaceName, cachedCharacters); } CharacterGeometry cachedChar; if (!cachedCharacters.TryGetValue(textChar, out cachedChar)) { cachedChar = InternalGetCharacterGeometryForCaching(textChar, font); cachedCharacters.Add(textChar, cachedChar); } return cachedChar; }
public void SetFontStyle(FontXStyle style) { FontId = FontId.WithStyle(style); }
public static FontInfo Create(Graphics g, FontX font) { FontInfo result = new FontInfo(); InternalGetInformation(g, result, font); return result; }
public void ScaleFont(double scale) { FontId = FontId.WithSize(scale * FontId.Size); }
/// <summary>Measures the string with the appropriate generic typographic format.</summary> /// <param name="g">The graphics context.</param> /// <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="PointD2D"/> structure.</returns> public static PointD2D MeasureString(Graphics g, string text, FontX font) { var result = g.MeasureString(text, GdiFontManager.ToGdi(font), PointF.Empty, _stringFormat); return new PointD2D(result.Width, result.Height); }
public override IMeasuredLabelItem[] GetMeasuredItems(Graphics g, FontX font, StringFormat strfmt, Altaxo.Data.AltaxoVariant[] items) { var litems = new MeasuredLabelItem[items.Length]; FontX localfont1 = font; FontX localfont2 = font.WithSize(font.Size * 2 / 3); var localstrfmt = (StringFormat)strfmt.Clone(); string[] firstp = new string[items.Length]; string[] middel = new string[items.Length]; string[] expos = new string[items.Length]; double[] mants = new double[items.Length]; float 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, GdiFontManager.ToGdi(localfont2), new PointF(0, 0), strfmt).Width); } 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, localstrfmt, _prefix + firstp[i] + mid, expos[i], _suffix, maxexposize); } return(litems); }
/// <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 PaintOneRange(Graphics g, IPlotArea layer, IPlotRange range, Processed2DPlotData pdata) { if (this._labelColumnProxy.Document == null) return; _cachedStringFormat.Alignment = GdiExtensionMethods.ToGdi(_alignmentX); _cachedStringFormat.LineAlignment = GdiExtensionMethods.ToGdi(_alignmentY); if (null != _attachedPlane) _attachedPlane = layer.UpdateCSPlaneID(_attachedPlane); var ptArray = pdata.PlotPointsInAbsoluteLayerCoordinates; Altaxo.Data.IReadableColumn labelColumn = this._labelColumnProxy.Document; bool isUsingVariableColorForLabelText = null != _cachedColorForIndexFunction && IsColorReceiver; bool isUsingVariableColorForLabelBackground = null != _cachedColorForIndexFunction && (null != _backgroundStyle && _backgroundStyle.SupportsBrush && (_backgroundColorLinkage == ColorLinkage.Dependent || _backgroundColorLinkage == ColorLinkage.PreserveAlpha)); bool isUsingVariableColor = isUsingVariableColorForLabelText || isUsingVariableColorForLabelBackground; BrushX clonedTextBrush = null; BrushX clonedBackBrush = null; if (isUsingVariableColorForLabelText) clonedTextBrush = _brush.Clone(); if (isUsingVariableColorForLabelBackground) clonedBackBrush = _backgroundStyle.Brush.Clone(); // save the graphics stat since we have to translate the origin var gs = g.Save(); double xpos = 0, ypos = 0; double xpre, ypre; double xdiff, ydiff; bool isFormatStringContainingBraces = _labelFormatString?.IndexOf('{') >= 0; var culture = System.Threading.Thread.CurrentThread.CurrentCulture; bool mustUseLogicalCoordinates = null != this._attachedPlane || 0 != _cachedLogicalShiftX || 0 != _cachedLogicalShiftY; int lower = range.LowerBound; int upper = range.UpperBound; for (int j = lower; j < upper; j+=_skipFrequency) { int originalRowIndex = range.GetOriginalRowIndexFromPlotPointIndex(j); string label; if (string.IsNullOrEmpty(_labelFormatString)) { label = labelColumn[originalRowIndex].ToString(); } else if (!isFormatStringContainingBraces) { label = labelColumn[originalRowIndex].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[originalRowIndex], originalRowIndex, pdata.GetPhysical(0, originalRowIndex), pdata.GetPhysical(1, originalRowIndex), pdata.GetPhysical(2, originalRowIndex)); } if (string.IsNullOrEmpty(label)) continue; double localSymbolSize = _symbolSize; if (null != _cachedSymbolSizeForIndexFunction) { localSymbolSize = _cachedSymbolSizeForIndexFunction(originalRowIndex); } 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) { Color c = _cachedColorForIndexFunction(originalRowIndex); if (isUsingVariableColorForLabelText) { clonedTextBrush.Color = new NamedColor(AxoColor.FromArgb(c.A, c.R, c.G, c.B), "e"); } if (isUsingVariableColorForLabelBackground) { if (_backgroundColorLinkage == ColorLinkage.PreserveAlpha) clonedBackBrush.Color = new NamedColor(AxoColor.FromArgb(clonedBackBrush.Color.Color.A, c.R, c.G, c.B), "e"); else clonedBackBrush.Color = 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, originalRowIndex); r3d.RX += _cachedLogicalShiftX; r3d.RY += _cachedLogicalShiftY; if (null != this._attachedPlane) { var pp = layer.CoordinateSystem.GetPointOnPlane(this._attachedPlane, r3d); xpre = pp.X; ypre = pp.Y; } else { PointD3D pt; layer.CoordinateSystem.LogicalToLayerCoordinates(r3d, out xpre, out ypre); } } else // no shifting, thus we can use layer coordinates { xpre = ptArray[j].X; ypre = ptArray[j].Y; } xdiff = xpre - xpos; ydiff = ypre - ypos; xpos = xpre; ypos = ypre; g.TranslateTransform((float)xdiff, (float)ydiff); if (this._rotation != 0) g.RotateTransform((float)-this._rotation); this.PaintOneItem(g, label, localSymbolSize, clonedTextBrush, clonedBackBrush); if (this._rotation != 0) g.RotateTransform((float)this._rotation); } g.Restore(gs); // Restore the graphics state }
public TextGraphic(PointD2D graphicPosition, string text, FontX textFont, NamedColor textColor) : base(new ItemLocationDirectAutoSize()) { this.SetPosition(graphicPosition, Main.EventFiring.Suppressed); this.Font = textFont; this.Text = text; this.Color = textColor; }
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; } }
protected CharacterGeometry InternalGetCharacterGeometryForCaching(char textChar, FontX font) { var charOutline = InternalGetCharacterOutlineForCaching(textChar, font); // get the - already simplified - polygonal shape of the character var polygons = charOutline.Outline; var polygonsWithNormal = new List<PolygonClosedWithNormalsD2D>(polygons.Select(poly => new PolygonClosedWithNormalsD2D(poly))); // get the polygons with normal, used to form the walls of the character var indexedTriangles = Triangulate(polygons); // Triangles that can be used for the front and the back side of the character var result = new CharacterGeometry( polygonsWithNormal, indexedTriangles, charOutline.FontSize, charOutline.LineSpacing, charOutline.Baseline, charOutline.AdvanceWidth, charOutline.LeftSideBearing, charOutline.RightSideBearing); return result; }
/// <summary> /// Gets the raw character outline, i.e. the polygonal shape that forms a character. The polygons are in their raw form, i.e. not simplified. /// </summary> /// <param name="textChar">The text character.</param> /// <param name="font">The font. The font size of this font is ignored, because it is given in the next parameter.</param> /// <param name="fontSize">Size of the font.</param> /// <returns>The list of polygons which forms the character.</returns> protected virtual RawCharacterOutline GetRawCharacterOutline(char textChar, FontX font, double fontSize) { throw new NotImplementedException("This is not implemented here, because it should be implemented in a derived class. This class should then set the static instance of this class to an instance of the derived class."); }
public static FontInfo Create(Graphics g, FontX font) { var result = new FontInfo(); InternalGetInformation(g, result, font); return result; }