在 XPS 文件中使用可视化画笔 | Python

可视化画笔是图形设计和软件开发环境中创建视觉上引人注目的动态设计的强大工具。它们用于使用视觉内容(例如图像、渐变或其他图形元素)填充或描边形状,从而允许您使用一个视觉元素绘制另一个视觉元素。

更专业的术语是,可视化画笔是一种引用视觉对象(例如图像或 UI 元素)的画笔,它使用该对象来定义形状或路径的外观。当应用于形状时,可视化画笔会在形状的边界内渲染引用的视觉对象。它们可用于使用图像填充形状、创建图案或纹理,甚至应用复杂的图形效果。

使用可视化画笔添加网格

Aspose.Page for Python via .NET 提供了 XpsVisualBrush 类,使您能够向 XPS 文档添加网格。为此,您必须指定 XpsPathGeometry 并将 XpsCanvas 添加到 XpsDocument 类的对象。以下代码片段演示了向 XPS 文档添加网格的完整功能:

 1# The path to the documents directory.
 2data_dir = Util.get_data_dir_working_with_visual_brush()
 3
 4doc = XpsDocument()
 5# Geometry for the magenta grid VisualBrush
 6path_geometry = doc.create_path_geometry()
 7path_geometry.add_segment(doc.create_poly_line_segment(
 8[ aspose.pydrawing.PointF(240, 5), aspose.pydrawing.PointF(240, 310), aspose.pydrawing.PointF(0, 310) ], True))
 9path_geometry[0].start_point = aspose.pydrawing.PointF(0, 5)
10
11# Canvas for the magenta grid VisualBrush
12visual_canvas = doc.create_canvas()
13
14visual_path = visual_canvas.add_path(
15doc.create_path_geometry("M 0,4 L 4,4 4,0 6,0 6,4 10,4 10,6 6,6 6,10 4,10 4,6 0,6 Z"))
16visual_path.fill = doc.create_solid_color_brush(doc.create_color(1, .61, 0.1, 0.61))
17
18grid_path = doc.create_path(path_geometry)
19#Create a Visual Brush, it is specified by some XPS fragment (vector graphics and glyphs)
20visualBrush: XpsVisualBrush = doc.create_visual_brush(visual_canvas,
21    aspose.pydrawing.RectangleF(0, 0, 10, 10), aspose.pydrawing.RectangleF(0, 0, 10, 10))
22grid_path.fill = visualBrush
23visualBrush.tile_mode = XpsTileMode.TILE
24# New canvas
25canvas = doc.add_canvas()
26canvas.render_transform = doc.create_matrix(1, 0, 0, 1, 268, 70)
27# Add a grid
28canvas.add_path(path_geometry)
29# Red transparent rectangle in the middle top
30path = canvas.add_path(doc.create_path_geometry("M 30,20 l 258.24,0 0,56.64 -258.24,0 Z"))
31path = canvas.add_path(doc.create_path_geometry("M 10,10 L 228,10 228,100 10,100"))
32path.fill = doc.create_solid_color_brush(doc.create_color(1.0, 0.0, 0.0))
33path.opacity = 0.7
34# Save the resultant XPS document
35doc.save(data_dir + "AddGrid_out.xps")

请参阅 .NETJavaC++ 中 XPS 文档中可视化画笔的使用方法。


结果如下

添加网格

您可以从 GitHub下载示例和数据文件。

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.