public static CATextLayer ToShape(this TextPath element) { var text = new CATextLayer(); text.FontSize = element.FontSize; return(text); }
/// <summary> /// Sets the leaf style. /// </summary> /// <param name="obj">The path.</param> /// <param name="style">The stem leaf to set.</param> /// <returns>The same instance so that multiple calls can be chained.</returns> public static TextPath LeafStyle(this TextPath obj, Style style) { if (obj is null) { throw new ArgumentNullException(nameof(obj)); } obj.LeafStyle = style; return(obj); }
protected override List <byte> GetBytes() { var bytes = base.GetBytes(); bytes.AddRange(Encoding.UTF8.GetBytes(TextPath.ToSvgString())); bytes.AddRange(BitConverter.GetBytes(Stretch)); bytes.AddRange(BitConverter.GetBytes(PathStart)); bytes.AddRange(BitConverter.GetBytes(PathEnd)); return(bytes); }
private Path GetDrawingTextPath(float dpi = 72) { var path = (Path)TextPath.Clone(); if (!Utils.EqualsOfFloatNumbers(Angle, 0)) { path.RotateAt(-Angle, path.GetFirstPoint()); } if (!Utils.EqualsOfFloatNumbers(72, dpi)) { path.Scale(dpi / 72, dpi / 72); } return(path); }
public void TransformTest() { var fontInfo = new FontInfo(FontFamily.GenericSansSerif, FontStyle.Regular); var scaleRatios = new[] { 100F, 10F, 1F }; var points = new[] { new PointF(0, 0), new PointF(0, 1080), new PointF(1920, -30), new PointF(1950, 1110) }; foreach (var scaleRatio in scaleRatios) { using (var bitmap = new Bitmap(1920, 1080)) { using (var graphics = Graphics.FromImage(bitmap)) { foreach (var point in points) { for (int i = -180; i < 180; i += 30) { var textPath = new TextPath("△--+--▽", fontInfo, 10.8F); textPath.Transform(scaleRatio, i, point); graphics.DrawPath(Pens.White, textPath.Path); } } } var fileName = MethodBase.GetCurrentMethod().Name + $"Result{scaleRatio}.bmp"; var filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), fileName); bitmap.Save(filePath); Assert.IsTrue(File.Exists(filePath)); } } }
protected internal override void UpdateSize() { if (ValidRect) { return; } RotatedRectangleF textRect; if (!TextPath.IsEmpty) { var dpi = Canvas != null ? 96 * Canvas.Zoom : 72; textRect = new RotatedRectangleF(MeasureText(dpi)); textRect.Scale(72 / dpi, 72 / dpi); var firstPoint = TextPath.GetFirstPoint(); // Move text rectangle to the text path's first point because GetBlackBox returns an empty rectangle (in location 0:0) when text is empty if (textRect.IsEmpty) { textRect.CenterX = firstPoint.X; textRect.CenterY = firstPoint.Y; } textRect.RotateAt(Angle, firstPoint); } else { textRect = new RotatedRectangleF(); } Path = Path.CreateRectanglePath(textRect.ToRectangleF()); Transform.Clear(keepAngle: true); ActualAngle = Transform.Angle; ValidRect = true; }
public override IImmagine applica(IImmagine immagineSorgente, Correzione correzione) { Scritta scritta = (Scritta)correzione; // Ricavo la bitmap sorgente BitmapSource bmpSorgente = ((ImmagineWic)immagineSorgente).bitmapSource; var ww = bmpSorgente.PixelWidth; var hh = bmpSorgente.PixelHeight; // -- creo un contenitore che mi permette di avere il controllo completo del posizionamento Panel contenitore = new Grid(); contenitore.Width = ww; contenitore.Height = hh; // contenitore.VerticalAlignment = VerticalAlignment.Center; // contenitore.HorizontalAlignment = HorizontalAlignment.Center; Image image = new Image(); image.BeginInit(); image.Source = bmpSorgente; image.EndInit(); contenitore.Children.Add(image); /* * Rect rectContenitore = new Rect( 0, 0, scritta.rifContenitoreW, scritta.rifContenitoreH ); * Rect rectScrittaOrig = new Rect( scritta.left, scritta.top, scritta.width, scritta.height ); * * Size nuovaSizeFoto = new Size( ww, hh ); * * Rect newRect = Geometrie.proporziona( rectScrittaOrig, rectContenitore, nuovaSizeFoto ); */ TextPath textPath = new TextPath(); textPath.Text = scritta.testo; textPath.FontFamily = new FontFamily(scritta.fontFamily); textPath.FontSize = scritta.fontSize; if (scritta.fillImage == null) { textPath.Fill = (SolidColorBrush) new BrushConverter().ConvertFromString(scritta.fillColor); } textPath.Stroke = (SolidColorBrush) new BrushConverter().ConvertFromString(scritta.strokeColor); textPath.StrokeThickness = scritta.strokeThickness; Viewbox viewBox = new Viewbox(); viewBox.Child = textPath; Canvas.SetZIndex(viewBox, 10); contenitore.Children.Add(viewBox); var size = new Size(ww, hh); contenitore.Measure(size); contenitore.Arrange(new Rect(size)); TransformGroup gruppo = new TransformGroup(); // ROTAZIONE if (scritta.rotazione != null) { RotateTransform rot = new RotateTransform(scritta.rotazione.gradi); // La rotazione avviene sempre nel centro dell'elemento var l = Double.IsNaN(Canvas.GetLeft(viewBox)) ? 0 : Canvas.GetLeft(viewBox); var t = Double.IsNaN(Canvas.GetTop(viewBox)) ? 0 : Canvas.GetTop(viewBox); rot.CenterX = l + (viewBox.ActualWidth / 2); rot.CenterY = t + (viewBox.ActualHeight / 2); // TransformGroup tg = new TransformGroup(); // tg.Children.Add( rot ); gruppo.Children.Add(rot); } // TRASLAZIONE (move) if (scritta.traslazione != null) { // devo riproporzionare le coordinate di origine a quelle attuali. // spostaX : oldW = newSpostaH : newW // var newOffsetX = contenitore.ActualWidth * scritta.traslazione.offsetX / scritta.traslazione.rifW; var newOffsetY = contenitore.ActualHeight * scritta.traslazione.offsetY / scritta.traslazione.rifH; TranslateTransform tre = new TranslateTransform(newOffsetX, newOffsetY); gruppo.Children.Add(tre); } if (scritta.zoom != null) { ScaleTransform stx = new ScaleTransform(scritta.zoom.fattore, scritta.zoom.fattore); gruppo.Children.Add(stx); stx.CenterX = (viewBox.RenderSize.Width / 2); stx.CenterY = (viewBox.RenderSize.Height / 2); } if (gruppo.Children.Count > 0) { viewBox.RenderTransform = gruppo; } contenitore.InvalidateMeasure(); contenitore.InvalidateArrange(); contenitore.Measure(size); contenitore.Arrange(new Rect(size)); /* * Rect rectSotto = new Rect( 0, 0, bmpSorgente.PixelWidth, bmpSorgente.PixelHeight ); * ImageDrawing drawingSotto = new ImageDrawing( bmpSorgente, rectSotto ); */ RenderTargetBitmap bmp = new RenderTargetBitmap(ww, hh, 96, 96, PixelFormats.Pbgra32); bmp.Render(contenitore); BmpBitmapEncoder enc = new BmpBitmapEncoder(); enc.Frames.Add(BitmapFrame.Create(bmp)); byte[] imagebit; //You can save your copy data in byte[]. using (MemoryStream stream = new MemoryStream()) { enc.Save(stream); imagebit = stream.ToArray(); stream.Close(); } var bitmap = new BitmapImage(); using (var stream = new MemoryStream(imagebit)) { bitmap.BeginInit(); bitmap.StreamSource = stream; bitmap.CacheOption = BitmapCacheOption.OnLoad; bitmap.EndInit(); bitmap.Freeze(); } return(new ImmagineWic(bitmap)); }
private Math.PointF GetDrawingFirstPoint(float dpi = 72) { return(Utils.EqualsOfFloatNumbers(72, dpi) ? new Math.PointF(TextPath.GetFirstPoint()) : new Math.PointF(TextPath.GetFirstPoint()).Scale(dpi / 72, dpi / 72)); }
void Update() { if (Text == null || TextPath == null || _layoutPanel == null || !_layoutHasValidSize) { return; } List <Point> intersectionPoints; intersectionPoints = GeometryHelper.GetIntersectionPoints(TextPath.GetFlattenedPathGeometry(), _segmentLengths); _layoutPanel.Children.Clear(); _layoutPanel.Margin = new Thickness(FontSize); for (int i = 0; i < intersectionPoints.Count - 1; i++) { double oppositeLen = Math.Sqrt(Math.Pow(intersectionPoints[i].X + _segmentLengths[i] - intersectionPoints[i + 1].X, 2.0) + Math.Pow(intersectionPoints[i].Y - intersectionPoints[i + 1].Y, 2.0)) / 2.0; double hypLen = Math.Sqrt(Math.Pow(intersectionPoints[i].X - intersectionPoints[i + 1].X, 2.0) + Math.Pow(intersectionPoints[i].Y - intersectionPoints[i + 1].Y, 2.0)); double ratio = oppositeLen / hypLen; if (ratio > 1.0) { ratio = 1.0; } else if (ratio < -1.0) { ratio = -1.0; } //double angle = 0.0; double angle = 2.0 * Math.Asin(ratio) * 180.0 / Math.PI; // adjust sign on angle if ((intersectionPoints[i].X + _segmentLengths[i]) > intersectionPoints[i].X) { if (intersectionPoints[i + 1].Y < intersectionPoints[i].Y) { angle = -angle; } } else { if (intersectionPoints[i + 1].Y > intersectionPoints[i].Y) { angle = -angle; } } TextBlock currTextBlock = _textBlocks[i]; RotateTransform rotate = new RotateTransform(angle); TranslateTransform translate = new TranslateTransform(intersectionPoints[i].X, intersectionPoints[i].Y - currTextBlock.DesiredSize.Height); TransformGroup transformGrp = new TransformGroup(); transformGrp.Children.Add(rotate); transformGrp.Children.Add(translate); currTextBlock.RenderTransform = transformGrp; _layoutPanel.Children.Add(currTextBlock); if (DrawLinePath == true) { Line line = new Line(); line.X1 = intersectionPoints[i].X; line.Y1 = intersectionPoints[i].Y; line.X2 = intersectionPoints[i + 1].X; line.Y2 = intersectionPoints[i + 1].Y; line.Stroke = Brushes.Black; _layoutPanel.Children.Add(line); } } // don't draw path if already drawing line path if (DrawPath == true && DrawLinePath == false) { Path path = new Path(); path.Data = TextPath; path.Stroke = Brushes.Black; _layoutPanel.Children.Add(path); } }
public void AcceptAttributeTextPath(TextPath textPath, PrintContext parameter) { parameter.WriteLine("Text Path: {0}", textPath.Path); }
public override int GetHashCode() { return(TextPath != null ? TextPath.GetHashCode() : string.Empty.GetHashCode()); }
public virtual void AcceptAttributeTextPath(TextPath textPath, T parameter) { // intentionally left blank }
/// <summary> /// Sets the stem color. /// </summary> /// <param name="obj">The path.</param> /// <param name="color">The stem color.</param> /// <returns>The same instance so that multiple calls can be chained.</returns> public static TextPath StemColor(this TextPath obj, Color color) { return(StemStyle(obj, new Style(foreground: color))); }
/// <summary> /// Sets the root color. /// </summary> /// <param name="obj">The path.</param> /// <param name="color">The root color.</param> /// <returns>The same instance so that multiple calls can be chained.</returns> public static TextPath RootColor(this TextPath obj, Color color) { return(RootStyle(obj, new Style(foreground: color))); }
/// <summary> /// Sets the separator color. /// </summary> /// <param name="obj">The path.</param> /// <param name="color">The separator color.</param> /// <returns>The same instance so that multiple calls can be chained.</returns> public static TextPath SeparatorColor(this TextPath obj, Color color) { return(SeparatorStyle(obj, new Style(foreground: color))); }
/// <summary> /// Sets the leaf color. /// </summary> /// <param name="obj">The path.</param> /// <param name="color">The leaf color.</param> /// <returns>The same instance so that multiple calls can be chained.</returns> public static TextPath LeafColor(this TextPath obj, Color color) { return(LeafStyle(obj, new Style(foreground: color))); }
static void AddWatermark(WordprocessingDocument doc, string textWatermark) { if (doc.MainDocumentPart.HeaderParts.Count() == 0) { doc.MainDocumentPart.DeleteParts(doc.MainDocumentPart.HeaderParts); var newHeaderPart = doc.MainDocumentPart.AddNewPart <HeaderPart>(); var rId = doc.MainDocumentPart.GetIdOfPart(newHeaderPart); var headerRef = new HeaderReference(); headerRef.Id = rId; var sectionProps = doc.MainDocumentPart.Document.Body.Elements <SectionProperties>().LastOrDefault(); if (sectionProps == null) { sectionProps = new SectionProperties(); doc.MainDocumentPart.Document.Body.Append(sectionProps); } sectionProps.RemoveAllChildren <HeaderReference>(); sectionProps.Append(headerRef); newHeaderPart.Header = MakeHeader(); newHeaderPart.Header.Save(); } foreach (HeaderPart headerPart in doc.MainDocumentPart.HeaderParts) { var sdtBlock1 = new SdtBlock(); var sdtProperties1 = new SdtProperties(); var sdtId1 = new SdtId() { Val = 87908844 }; var sdtContentDocPartObject1 = new SdtContentDocPartObject(); var docPartGallery1 = new DocPartGallery() { Val = "Watermarks" }; var docPartUnique1 = new DocPartUnique(); sdtContentDocPartObject1.Append(docPartGallery1); sdtContentDocPartObject1.Append(docPartUnique1); sdtProperties1.Append(sdtId1); sdtProperties1.Append(sdtContentDocPartObject1); var sdtContentBlock1 = new SdtContentBlock(); var paragraph2 = new Paragraph() { RsidParagraphAddition = "00656E18", RsidRunAdditionDefault = "00656E18" }; var paragraphProperties2 = new ParagraphProperties(); var paragraphStyleId2 = new ParagraphStyleId() { Val = "Header" }; paragraphProperties2.Append(paragraphStyleId2); var run1 = new Run(); var runProperties1 = new RunProperties(); var noProof1 = new NoProof(); var languages1 = new Languages() { EastAsia = "zh-TW" }; runProperties1.Append(noProof1); runProperties1.Append(languages1); var picture1 = new Picture(); var shapetype1 = new Shapetype() { Id = "_x0000_t136", CoordinateSize = "21600,21600", OptionalNumber = 136, Adjustment = "10800", EdgePath = "m@7,l@8,m@5,21600l@6,21600e" }; var formulas1 = new Formulas(); var formula1 = new Formula() { Equation = "sum #0 0 10800" }; var formula2 = new Formula() { Equation = "prod #0 2 1" }; var formula3 = new Formula() { Equation = "sum 21600 0 @1" }; var formula4 = new Formula() { Equation = "sum 0 0 @2" }; var formula5 = new Formula() { Equation = "sum 21600 0 @3" }; var formula6 = new Formula() { Equation = "if @0 @3 0" }; var formula7 = new Formula() { Equation = "if @0 21600 @1" }; var formula8 = new Formula() { Equation = "if @0 0 @2" }; var formula9 = new Formula() { Equation = "if @0 @4 21600" }; var formula10 = new Formula() { Equation = "mid @5 @6" }; var formula11 = new Formula() { Equation = "mid @8 @5" }; var formula12 = new Formula() { Equation = "mid @7 @8" }; var formula13 = new Formula() { Equation = "mid @6 @7" }; var formula14 = new Formula() { Equation = "sum @6 0 @5" }; formulas1.Append(formula1); formulas1.Append(formula2); formulas1.Append(formula3); formulas1.Append(formula4); formulas1.Append(formula5); formulas1.Append(formula6); formulas1.Append(formula7); formulas1.Append(formula8); formulas1.Append(formula9); formulas1.Append(formula10); formulas1.Append(formula11); formulas1.Append(formula12); formulas1.Append(formula13); formulas1.Append(formula14); var path1 = new Path() { AllowTextPath = TrueFalseValue.FromBoolean(true), ConnectionPointType = ConnectValues.Custom, ConnectionPoints = "@9,0;@10,10800;@11,21600;@12,10800", ConnectAngles = "270,180,90,0" }; var textPath1 = new TextPath() { On = TrueFalseValue.FromBoolean(true), FitShape = TrueFalseValue.FromBoolean(true) }; var shapeHandles1 = new ShapeHandles(); var shapeHandle1 = new ShapeHandle() { Position = "#0,bottomRight", XRange = "6629,14971" }; shapeHandles1.Append(shapeHandle1); var lock1 = new Lock { Extension = ExtensionHandlingBehaviorValues.Edit, TextLock = TrueFalseValue.FromBoolean(true), ShapeType = TrueFalseValue.FromBoolean(true) }; shapetype1.Append(formulas1); shapetype1.Append(path1); shapetype1.Append(textPath1); shapetype1.Append(shapeHandles1); shapetype1.Append(lock1); var shape1 = new Shape() { Id = "PowerPlusWaterMarkObject357922611", Style = "position:absolute;left:0;text-align:left;margin-left:0;margin-top:0;width:527.85pt;height:131.95pt;rotation:315;z-index:-251656192;mso-position-horizontal:center;mso-position-horizontal-relative:margin;mso-position-vertical:center;mso-position-vertical-relative:margin", OptionalString = "_x0000_s2049", AllowInCell = TrueFalseValue.FromBoolean(true), FillColor = "silver", Stroked = TrueFalseValue.FromBoolean(false), Type = "#_x0000_t136" }; var fill1 = new Fill() { Opacity = ".5" }; TextPath textPath2 = new TextPath() { Style = "font-family:\"Calibri\";font-size:1pt", String = textWatermark }; var textWrap1 = new TextWrap() { AnchorX = HorizontalAnchorValues.Margin, AnchorY = VerticalAnchorValues.Margin }; shape1.Append(fill1); shape1.Append(textPath2); shape1.Append(textWrap1); picture1.Append(shapetype1); picture1.Append(shape1); run1.Append(runProperties1); run1.Append(picture1); paragraph2.Append(paragraphProperties2); paragraph2.Append(run1); sdtContentBlock1.Append(paragraph2); sdtBlock1.Append(sdtProperties1); sdtBlock1.Append(sdtContentBlock1); headerPart.Header.Append(sdtBlock1); headerPart.Header.Save(); //break; } }