public SVGPath(String unicodeHex, String path) { String hex = ""; CanvasDevice device = CanvasDevice.GetSharedDevice(); hex = unicodeHex; _ID = int.Parse(unicodeHex.Replace(";", ""), System.Globalization.NumberStyles.HexNumber);//Convert.ToInt32(hex); CanvasPathBuilder pb = new CanvasPathBuilder(device); parsePath(pb, path); //L 1.5 = 2650 pixel units in the svg font file //double L1_5 = 2650; //_cg = _cg.Transform(Matrix3x2.CreateScale(0.2f)); _cg = _cg.Transform(Matrix3x2.CreateScale(0.0188679245283019f)); _bounds = _cg.ComputeBounds(); _ccgFill = CanvasCachedGeometry.CreateFill(_cg); }
public SVGPath(SVGPath path) { _ID = path._ID; _cg = path._cg.Transform(Matrix3x2.Identity); _bounds = _cg.ComputeBounds(); _ccgFill = CanvasCachedGeometry.CreateFill(_cg); }
public static (string Path, Rect Bounds) GetGeometry( Character selectedChar, CharacterRenderingOptions options) { /* * Note: this only constructs the monochrome version * of the glyph. * * Drop into C++/CX for color / multi-variant glyphs. */ using CanvasGeometry geom = CreateGeometry(selectedChar, options); var bounds = geom.ComputeBounds(); var interop = Utils.GetInterop(); var s = interop.GetPathData(geom); if (string.IsNullOrWhiteSpace(s.Path)) { return(s.Path, bounds); } var t = s.Transform.Translation; bounds = new Rect(t.X - bounds.Left, -bounds.Top + t.Y, bounds.Width, bounds.Height); return(s.Path, bounds); }
public static (string Path, Rect Bounds) GetGeometry( float size, FontVariant selectedVariant, Character selectedChar, CanvasTextLayoutAnalysis analysis, CanvasTypography typography) { using (CanvasGeometry geom = CreateGeometry(size, selectedVariant, selectedChar, analysis, typography)) { /* * Unfortunately this only constructs a monochrome path, if we want color * Win2D does not yet expose the necessary API's to get the individual glyph * layers that make up a color glyph. * * We'll need to handle this in C++/CX if we want to do this at some point. */ var bounds = geom.ComputeBounds(); var interop = SimpleIoc.Default.GetInstance <Interop>(); var s = interop.GetPathData(geom); var t = s.Transform.Translation; bounds = new Rect(t.X - bounds.Left, -bounds.Top + t.Y, bounds.Width, bounds.Height); return(s.Path, bounds); } }
// Used for both baseGeometry and stretchedGeometry void ComputeGeometryBounds(CanvasGeometry geometry, ref winFound.Rect geometryBounds, ref winFound.Rect geometryStrokeBounds) { if (geometry != null) { geometryBounds = geometry.ComputeBounds(); geometryStrokeBounds = geometry.ComputeStrokeBounds(strokeWidth, strokeStyle); } else { geometryBounds = new winFound.Rect(); geometryStrokeBounds = new winFound.Rect(); } }
public SVGPath(String unicodeHex, String path, ICanvasResourceCreator rc) { _ID = int.Parse(unicodeHex.Replace(";", ""), System.Globalization.NumberStyles.HexNumber); CanvasPathBuilder pb = new CanvasPathBuilder(rc); parsePath(pb, path); _cg = _cg.Transform(Matrix3x2.CreateScale(0.2f)); _bounds = _cg.ComputeBounds(); _ccgFill = CanvasCachedGeometry.CreateFill(_cg); }
/// <summary> /// Creates a scale & translation matrix /// </summary> /// <param name="width"></param> /// <param name="height"></param> /// <param name="bounds"></param> /// <param name="outBounds"></param> /// <returns></returns> public Matrix3x2 CreateMatrix(int width, int height, out Rect outBounds, out Matrix3x2 mScale, out Matrix3x2 mTranslate) { float scale = 1f; Rect rect = new Rect(_bounds.X, _bounds.Y, _bounds.Width, _bounds.Height); //_cg.ComputeBounds();//(testMatrix, testPen); mScale = new Matrix3x2(); mTranslate = new Matrix3x2(); float sx = (float)(width / rect.Width); float sy = (float)(height / rect.Height); if (sx < sy) { scale = sx; } else { scale = sy; } mScale = Matrix3x2.CreateScale(scale, scale); outBounds = new Rect(0, 0, _bounds.Width * scale, _bounds.Height * scale); _cgBounds = CanvasGeometry.CreateRectangle(_cg.Device, _bounds); _cgBounds = _cgBounds.Transform(mScale); rect = _cgBounds.ComputeBounds(); float transx = 0; float transy = 0; if (rect.X < 0) { transx = (float)(rect.X * -1.0f); } if (rect.Y < 0) { transy = (float)(rect.Y * -1.0f); } mTranslate = Matrix3x2.CreateTranslation(transx, transy); //return Matrix3x2.Add(mScale, mTranslate); return(Matrix3x2.Multiply(mScale, mTranslate)); }//
private CanvasGeometry GetLayoutGeometry(CanvasControl sender) { CanvasGeometry geometry = null; if (CurrentLayoutShapeOption == LayoutShapeOption.Box) { geometry = CanvasGeometry.CreateRectangle(sender, layoutBox); } else if (CurrentLayoutShapeOption == LayoutShapeOption.Ellipse) { float cx = (float)(layoutBox.Left + layoutBox.Right) / 2; float cy = (float)(layoutBox.Top + layoutBox.Bottom) / 2; float rx = cx - (float)layoutBox.Left; float ry = cy - (float)layoutBox.Top; geometry = CanvasGeometry.CreateEllipse(sender, cx, cy, rx, ry); } else if (CurrentLayoutShapeOption == LayoutShapeOption.Triangle) { CanvasPathBuilder pathBuilder = new CanvasPathBuilder(sender); pathBuilder.BeginFigure((float)layoutBox.Left, (float)layoutBox.Top); pathBuilder.AddLine((float)layoutBox.Left + (float)(layoutBox.Width), (float)layoutBox.Top); pathBuilder.AddLine((float)layoutBox.Left, (float)layoutBox.Top + (float)(layoutBox.Height)); pathBuilder.EndFigure(CanvasFigureLoop.Closed); geometry = CanvasGeometry.CreatePath(pathBuilder); } else if (CurrentLayoutShapeOption == LayoutShapeOption.TextOutline) { CanvasTextFormat textFormat = new CanvasTextFormat(); textFormat.FontWeight = Windows.UI.Text.FontWeights.ExtraBold; textFormat.WordWrapping = CanvasWordWrapping.NoWrap; textFormat.FontFamily = fontPicker.CurrentFontFamily; CanvasTextLayout textLayout = new CanvasTextLayout(sender, textLayoutBoxInput.Text, textFormat, 0, 0); geometry = CanvasGeometry.CreateText(textLayout); var bounds = geometry.ComputeBounds(); float scaleX = (float)layoutBox.Width / (float)bounds.Width; float scaleY = (float)layoutBox.Height / (float)bounds.Height; geometry = geometry.Transform( Matrix3x2.CreateTranslation(-(float)bounds.X, -(float)bounds.Y) * Matrix3x2.CreateScale(scaleX, scaleY) * Matrix3x2.CreateTranslation((float)layoutBox.X, (float)layoutBox.Y)); } return(geometry); }
}// public Matrix3x2 TransformToFitDimensions(int width, int height) { float scale = 1f; Rect rect = _cg.ComputeBounds();//(testMatrix, testPen); Matrix3x2 mScale = new Matrix3x2(); Matrix3x2 mTranslate = new Matrix3x2(); float sx = (float)(width / rect.Width); float sy = (float)(height / rect.Height); if (sx < sy) { scale = sx; } else { scale = sy; } mScale = Matrix3x2.CreateScale(scale, scale); _cg = _cg.Transform(mScale); rect = _cg.ComputeBounds();//(testMatrix, testPen); float transx = 0; float transy = 0; if (rect.X < 0) { transx = (float)(rect.X * -1.0f); } if (rect.Y < 0) { transy = (float)(rect.Y * -1.0f); } mTranslate = Matrix3x2.CreateTranslation(transx, transy); _cg = _cg.Transform(mTranslate); //return Matrix3x2.Add(mScale, mTranslate); return(Matrix3x2.Multiply(mScale, mTranslate)); }//
List <Rect> SplitGeometryIntoRectangles(CanvasGeometry geometry, float rectangleHeight, CanvasControl sender) { List <Rect> result = new List <Rect>(); var geometryBounds = geometry.ComputeBounds(); double left = geometryBounds.X; double top = geometryBounds.Y; double y = top; while (y < geometryBounds.Bottom) { var lineRegion = new Rect(left, y, geometryBounds.Width, rectangleHeight); var lineRegionGeometry = CanvasGeometry.CreateRectangle(sender, lineRegion); var compareResult = geometry.CompareWith(lineRegionGeometry); if (compareResult == CanvasGeometryRelation.Contains) { // The whole line fits. result.Add(lineRegion); } else if (compareResult == CanvasGeometryRelation.Disjoint) { // The line doesn't fit, so skip it. } else if (compareResult == CanvasGeometryRelation.Overlap) { var intersection = geometry.CombineWith(lineRegionGeometry, Matrix3x2.Identity, CanvasGeometryCombine.Intersect); PathReader pathReader = new PathReader(lineRegion); intersection.Simplify(CanvasGeometrySimplification.Lines).SendPathTo(pathReader); var rectangles = pathReader.GetRectangles(); rectangles.Sort(new RectangleComparer(CurrentTextDirection == TextDirection.RightToLeft)); result.AddRange(rectangles); } y += rectangleHeight; } return(result); }
static void DrawFaceInCenterOfGeometry(CanvasDrawingSession ds, CanvasGeometry geom) { if (geom == null) { return; } var bounds = geom.ComputeBounds(); var centerX = bounds.X + bounds.Width / 2; var centerY = bounds.Y + bounds.Height / 2; var center = new Vector2((float)centerX, (float)centerY); ds.DrawText("ಠ⌣ಠ", center, Colors.White, new CanvasTextFormat() { FontSize = 36, ParagraphAlignment = ParagraphAlignment.Center, VerticalAlignment = CanvasVerticalAlignment.Center }); }
public static (string Path, Rect Bounds) GetGeometry( float size, FontVariant selectedVariant, Character selectedChar, CanvasTextLayoutAnalysis analysis, CanvasTypography typography) { /* * Note: this only constructs the monochrome version * of the glyph. * * Drop into C++/CX for color / multi-variant glyphs. */ using CanvasGeometry geom = CreateGeometry(size, selectedVariant, selectedChar, analysis, typography); var bounds = geom.ComputeBounds(); var interop = Utils.GetInterop(); var s = interop.GetPathData(geom); var t = s.Transform.Translation; bounds = new Rect(t.X - bounds.Left, -bounds.Top + t.Y, bounds.Width, bounds.Height); return(s.Path, bounds); }
static void DrawFaceInCenterOfGeometry(CanvasDrawingSession ds, CanvasGeometry geom) { if (geom == null) return; var bounds = geom.ComputeBounds(); var centerX = bounds.X + bounds.Width / 2; var centerY = bounds.Y + bounds.Height / 2; var center = new Vector2((float)centerX, (float)centerY); ds.DrawText("ಠ⌣ಠ", center, Colors.White, new CanvasTextFormat() { FontSize = 36, HorizontalAlignment = CanvasHorizontalAlignment.Center, VerticalAlignment = CanvasVerticalAlignment.Center }); }
public static async Task ExportSvgAsync( ExportStyle style, InstalledFont selectedFont, FontVariant selectedVariant, Character selectedChar, CanvasTypography typography) { try { string name = GetFileName(selectedFont, selectedVariant, selectedChar, "svg"); if (await PickFileAsync(name, "SVG", new[] { ".svg" }) is StorageFile file) { CachedFileManager.DeferUpdates(file); var device = Utils.CanvasDevice; var textColor = style == ExportStyle.Black ? Colors.Black : Colors.White; /* SVG Exports render at fixed size - but a) they're vectors, and b) they're * inside an auto-scaling viewport. So rendersize is *largely* pointless */ float canvasH = 1024f, canvasW = 1024f, fontSize = 1024f; using (CanvasTextLayout layout = new CanvasTextLayout(device, $"{selectedChar.Char}", new CanvasTextFormat { FontSize = fontSize, FontFamily = selectedVariant.Source, FontStretch = selectedVariant.FontFace.Stretch, FontWeight = selectedVariant.FontFace.Weight, FontStyle = selectedVariant.FontFace.Style, HorizontalAlignment = CanvasHorizontalAlignment.Center }, canvasW, canvasH)) { layout.SetTypography(0, 1, typography); using (CanvasGeometry temp = CanvasGeometry.CreateText(layout)) { var b = temp.ComputeBounds(); double scale = Math.Min(1, Math.Min(canvasW / b.Width, canvasH / b.Height)); Matrix3x2 transform = Matrix3x2.CreateTranslation(new Vector2((float)-b.Left, (float)-b.Top)) * Matrix3x2.CreateScale(new Vector2((float)scale)); using (CanvasGeometry geom = temp.Transform(transform)) { /* * Unfortunately this only constructs a monochrome path, if we want color * Win2D does not yet expose the neccessary API's to get the individual glyph * layers that make up a colour glyph. * * We'll need to handle this in C++/CX if we want to do this at some point. */ SVGPathReciever rc = new SVGPathReciever(); geom.SendPathTo(rc); Rect bounds = geom.ComputeBounds(); using (CanvasSvgDocument document = Utils.GenerateSvgDocument(device, bounds.Width, bounds.Height, rc)) { ((CanvasSvgNamedElement)document.Root.FirstChild).SetColorAttribute("fill", textColor); await Utils.WriteSvgAsync(document, file); } } } } await CachedFileManager.CompleteUpdatesAsync(file); } } catch (Exception ex) { await SimpleIoc.Default.GetInstance <IDialogService>() .ShowMessageBox(ex.Message, Localization.Get("SaveImageError")); } }
public SVGPath(String unicodeHex, String path, ICanvasResourceCreator rc) { _ID = Convert.ToInt32(unicodeHex); CanvasPathBuilder pb = new CanvasPathBuilder(rc); parsePath(pb, path); _cg = _cg.Transform(Matrix3x2.CreateScale(0.2f)); _bounds = _cg.ComputeBounds(); _ccgFill = CanvasCachedGeometry.CreateFill(_cg); }
}// public Matrix3x2 TransformToFitDimensions(int width, int height) { float scale = 1f; Rect rect = _cg.ComputeBounds();//(testMatrix, testPen); Matrix3x2 mScale = new Matrix3x2(); Matrix3x2 mTranslate = new Matrix3x2(); float sx = (float)(width / rect.Width); float sy = (float)(height / rect.Height); if (sx < sy) { scale = sx; } else { scale = sy; } mScale = Matrix3x2.CreateScale(scale, scale); _cg = _cg.Transform(mScale); rect = _cg.ComputeBounds();//(testMatrix, testPen); float transx = 0; float transy = 0; if (rect.X < 0) transx = (float)(rect.X * -1.0f); if (rect.Y < 0) transy = (float)(rect.Y * -1.0f); mTranslate = Matrix3x2.CreateTranslation(transx, transy); _cg = _cg.Transform(mTranslate); //return Matrix3x2.Add(mScale, mTranslate); return Matrix3x2.Multiply(mScale, mTranslate); }//
}// public void Transform(Matrix3x2 m) { _cg = _cg.Transform(m); _ccgFill = CanvasCachedGeometry.CreateFill(_cg); _bounds = _cg.ComputeBounds(); }
public SVGPath(String unicodeHex, String path) { String hex = ""; CanvasDevice device = CanvasDevice.GetSharedDevice(); hex = unicodeHex; _ID = Convert.ToInt32(hex); CanvasPathBuilder pb = new CanvasPathBuilder(device); parsePath(pb, path); //L 1.5 = 2650 pixel units in the svg font file //double L1_5 = 2650; //_cg = _cg.Transform(Matrix3x2.CreateScale(0.2f)); _cg = _cg.Transform(Matrix3x2.CreateScale(0.0188679245283019f)); _bounds = _cg.ComputeBounds(); _ccgFill = CanvasCachedGeometry.CreateFill(_cg); }
}// public void Transform(Matrix3x2 m) { _cg = _cg.Transform(m); _ccgFill = CanvasCachedGeometry.CreateFill(_cg); _bounds = _cg.ComputeBounds(); }
/// <summary> /// Creates a scale & translation matrix /// </summary> /// <param name="width"></param> /// <param name="height"></param> /// <param name="bounds"></param> /// <param name="outBounds"></param> /// <returns></returns> public Matrix3x2 CreateMatrix(int width, int height, out Rect outBounds, out Matrix3x2 mScale, out Matrix3x2 mTranslate) { float scale = 1f; Rect rect = new Rect(_bounds.X, _bounds.Y, _bounds.Width, _bounds.Height); //_cg.ComputeBounds();//(testMatrix, testPen); mScale = new Matrix3x2(); mTranslate = new Matrix3x2(); float sx = (float)(width / rect.Width); float sy = (float)(height / rect.Height); if (sx < sy) { scale = sx; } else { scale = sy; } mScale = Matrix3x2.CreateScale(scale, scale); outBounds = new Rect(0, 0, _bounds.Width * scale, _bounds.Height * scale); _cgBounds = CanvasGeometry.CreateRectangle(_cg.Device, _bounds); _cgBounds = _cgBounds.Transform(mScale); rect = _cgBounds.ComputeBounds(); float transx = 0; float transy = 0; if (rect.X < 0) transx = (float)(rect.X * -1.0f); if (rect.Y < 0) transy = (float)(rect.Y * -1.0f); mTranslate = Matrix3x2.CreateTranslation(transx, transy); //return Matrix3x2.Add(mScale, mTranslate); return Matrix3x2.Multiply(mScale, mTranslate); }//
public SVGPath(SVGPath path) { _ID = path._ID; _cg = path._cg.Transform(Matrix3x2.Identity); _bounds = _cg.ComputeBounds(); _ccgFill = CanvasCachedGeometry.CreateFill(_cg); }
public Rect computeBounds() { return(_cg.ComputeBounds()); }
public void CreateLoadingWave(Microsoft.Graphics.Canvas.UI.Xaml.ICanvasAnimatedControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasAnimatedDrawEventArgs args, Vector2 position, Color color) { if (rate >= 10) { percent++; rate = 0; } if (percent > 100) { percent = 0; } CanvasTextLayout textLayout = new CanvasTextLayout(sender, $"{percent}", new CanvasTextFormat() { FontSize = RadiusValue }, RadiusValue * 2, RadiusValue * 2); CanvasGeometry orignalText = CanvasGeometry.CreateText(textLayout); var rectText = orignalText.ComputeBounds(); var textOffsetX = (RadiusValue * 2 - textLayout.LayoutBoundsIncludingTrailingWhitespace.Width) / 2; var textOffsetY = (RadiusValue * 2 - textLayout.LayoutBoundsIncludingTrailingWhitespace.Height) / 2; orignalText = orignalText.Transform(Matrix3x2.CreateTranslation((float)textOffsetX + position.X, (float)textOffsetY + position.Y)); CanvasPathBuilder builder = new CanvasPathBuilder(sender); var offsetY = 2 * rate / 10 + percent * 2; builder.BeginFigure(0 + offsetX + position.X, RadiusValue * 2 - offsetY + position.Y); builder.AddCubicBezier(new Vector2(RadiusValue * 1 + offsetX + position.X, RadiusValue * 2 + RadiusValue / 3 - offsetY + position.Y), new Vector2(RadiusValue * 1 + offsetX + position.X, RadiusValue * 2 - RadiusValue / 3 - offsetY + position.Y), new Vector2(RadiusValue * 2 + offsetX + position.X, RadiusValue * 2 - offsetY + position.Y)); builder.AddCubicBezier(new Vector2(RadiusValue * 3 + offsetX + position.X, RadiusValue * 2 + RadiusValue / 3 - offsetY + position.Y), new Vector2(RadiusValue * 3 + offsetX + position.X, RadiusValue * 2 - RadiusValue / 3 - offsetY + position.Y), new Vector2(RadiusValue * 4 + offsetX + position.X, RadiusValue * 2 - offsetY + position.Y)); builder.AddLine(RadiusValue * 4 + offsetX + position.X, RadiusValue * 4 + position.Y); builder.AddLine(0 + offsetX + position.X, RadiusValue * 4 + position.Y); builder.EndFigure(CanvasFigureLoop.Closed); var wavePath = CanvasGeometry.CreatePath(builder); var circlePath = CanvasGeometry.CreateCircle(sender, new Vector2(RadiusValue, RadiusValue), RadiusValue); var backgroundPath = circlePath.CombineWith(wavePath, Matrix3x2.Identity, CanvasGeometryCombine.Intersect); var topText = orignalText.CombineWith(backgroundPath, Matrix3x2.Identity, CanvasGeometryCombine.Exclude); var drawnText = orignalText.CombineWith(backgroundPath, Matrix3x2.Identity, CanvasGeometryCombine.Intersect); args.DrawingSession.FillGeometry(backgroundPath, position, color); args.DrawingSession.FillGeometry(topText, color); args.DrawingSession.FillGeometry(drawnText, Colors.White); var borderCircle = CanvasGeometry.CreateCircle(sender, new Vector2(RadiusValue, RadiusValue), RadiusValue - 1); args.DrawingSession.DrawGeometry(borderCircle, position, color); offsetX--; if (offsetX <= -RadiusValue * 2) { offsetX = 0; } rate++; }