OfficeMathRenderer class

OfficeMathRenderer class

Provides methods to render an individual OfficeMath to a raster or vector image or to a Graphics object. To learn more, visit the Working with OfficeMath documentation article.

Inheritance: OfficeMathRendererNodeRendererBase

Constructors

NameDescription
OfficeMathRenderer(math)Initializes a new instance of this class.

Properties

NameDescription
bounds_in_pointsGets the actual bounds of the shape in points.
(Inherited from NodeRendererBase)
opaque_bounds_in_pointsGets the opaque bounds of the shape in points.
(Inherited from NodeRendererBase)
size_in_pointsGets the actual size of the shape in points.
(Inherited from NodeRendererBase)

Methods

NameDescription
get_bounds_in_pixels(scale, dpi)Calculates the bounds of the shape in pixels for a specified zoom factor and resolution.
(Inherited from NodeRendererBase)
get_bounds_in_pixels(scale, horizontal_dpi, vertical_dpi)Calculates the bounds of the shape in pixels for a specified zoom factor and resolution.
(Inherited from NodeRendererBase)
get_opaque_bounds_in_pixels(scale, dpi)Calculates the opaque bounds of the shape in pixels for a specified zoom factor and resolution.
(Inherited from NodeRendererBase)
get_opaque_bounds_in_pixels(scale, horizontal_dpi, vertical_dpi)Calculates the opaque bounds of the shape in pixels for a specified zoom factor and resolution.
(Inherited from NodeRendererBase)
get_size_in_pixels(scale, dpi)Calculates the size of the shape in pixels for a specified zoom factor and resolution.
(Inherited from NodeRendererBase)
get_size_in_pixels(scale, horizontal_dpi, vertical_dpi)Calculates the size of the shape in pixels for a specified zoom factor and resolution.
(Inherited from NodeRendererBase)
save(file_name, save_options)Renders the shape into an image and saves into a file.
(Inherited from NodeRendererBase)
save(file_name, save_options)Renders the shape into an SVG image and saves into a file.
(Inherited from NodeRendererBase)
save(stream, save_options)Renders the shape into an image and saves into a stream.
(Inherited from NodeRendererBase)
save(stream, save_options)Renders the shape into an SVG image and saves into a stream.
(Inherited from NodeRendererBase)

Examples

Shows how to measure and scale shapes.

doc = aw.Document(MY_DIR + "Office math.docx")

office_math = doc.get_child(aw.NodeType.OFFICE_MATH, 0, True).as_office_math()
renderer = aw.rendering.OfficeMathRenderer(office_math)

# Verify the size of the image that the OfficeMath object will create when we render it.
self.assertAlmostEqual(119.0, renderer.size_in_points.width, delta=0.25)
self.assertAlmostEqual(13.0, renderer.size_in_points.height, delta=0.1)

self.assertAlmostEqual(119.0, renderer.bounds_in_points.width, delta=0.25)
self.assertAlmostEqual(13.0, renderer.bounds_in_points.height, delta=0.1)

# Shapes with transparent parts may contain different values in the "opaque_bounds_in_points" properties.
self.assertAlmostEqual(119.0, renderer.opaque_bounds_in_points.width, delta=0.25)
self.assertAlmostEqual(14.2, renderer.opaque_bounds_in_points.height, delta=0.1)

# Get the shape size in pixels, with linear scaling to a specific DPI.
bounds = renderer.get_bounds_in_pixels(1.0, 96.0)

self.assertEqual(159, bounds.width)
self.assertEqual(18, bounds.height)

# Get the shape size in pixels, but with a different DPI for the horizontal and vertical dimensions.
bounds = renderer.get_bounds_in_pixels(1.0, 96.0, 150.0)
self.assertEqual(159, bounds.width)
self.assertEqual(28, bounds.height)

# The opaque bounds may vary here also.
bounds = renderer.get_opaque_bounds_in_pixels(1.0, 96.0)

self.assertEqual(159, bounds.width)
self.assertEqual(18, bounds.height)

bounds = renderer.get_opaque_bounds_in_pixels(1.0, 96.0, 150.0)

self.assertEqual(159, bounds.width)
self.assertEqual(30, bounds.height)

See Also