Aspose::Words::Rendering::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.

class OfficeMathRenderer : public NodeRendererBase

Methods

MethodDescription
OfficeMathRenderer(const System::SharedPtr<Aspose::Words::Math::OfficeMath> &)Initializes a new instance of this class.
GetBoundsInPixels(float, float)Calculates the bounds of the shape in pixels for a specified zoom factor and resolution.
GetBoundsInPixels(float, float, float)Calculates the bounds of the shape in pixels for a specified zoom factor and resolution.
GetOpaqueBoundsInPixels(float, float)Calculates the opaque bounds of the shape in pixels for a specified zoom factor and resolution.
GetOpaqueBoundsInPixels(float, float, float)Calculates the opaque bounds of the shape in pixels for a specified zoom factor and resolution.
GetSizeInPixels(float, float)Calculates the size of the shape in pixels for a specified zoom factor and resolution.
GetSizeInPixels(float, float, float)Calculates the size of the shape in pixels for a specified zoom factor and resolution.
RenderToScale(const System::SharedPtr<System::Drawing::Graphics> &, float, float, float)Renders the shape into a Graphics object to a specified scale.
RenderToSize(const System::SharedPtr<System::Drawing::Graphics> &, float, float, float, float)Renders the shape into a Graphics object to a specified size.
Save(const System::SharedPtr<System::IO::Stream> &, System::SharedPtr<Aspose::Words::Saving::ImageSaveOptions>)Renders the shape into an image and saves into a stream.
Save(const System::SharedPtr<System::IO::Stream> &, System::SharedPtr<Aspose::Words::Saving::SvgSaveOptions>)Renders the shape into an SVG image and saves into a stream.
Save(const System::String &, System::SharedPtr<Aspose::Words::Saving::ImageSaveOptions>)Renders the shape into an image and saves into a file.
Save(const System::String &, System::SharedPtr<Aspose::Words::Saving::SvgSaveOptions>)Renders the shape into an SVG image and saves into a file.
Save(std::basic_ostream<CharType, Traits> &, System::SharedPtr<Aspose::Words::Saving::ImageSaveOptions>)Renders the shape into an image and saves into a stream.
Save(std::basic_ostream<CharType, Traits> &, System::SharedPtr<Aspose::Words::Saving::SvgSaveOptions>)Renders the shape into an SVG image and saves into a stream.
get_BoundsInPoints() constGets the actual bounds of the shape in points.
get_OpaqueBoundsInPoints()Gets the opaque bounds of the shape in points.
get_SizeInPoints()Gets the actual size of the shape in points.

Examples

Shows how to measure and scale shapes.

auto doc = System::MakeObject<Aspose::Words::Document>(System::String(get_MyDir() + u"Office math.docx"));

auto officeMath = System::ExplicitCast<Aspose::Words::Math::OfficeMath>(doc->GetChild(NodeType::OfficeMath, 0, true));
auto renderer = System::MakeObject<Aspose::Words::Rendering::OfficeMathRenderer>(officeMath);

// Verify the size of the image that the OfficeMath object will create when we render it.
ASSERT_NEAR(renderer->get_SizeInPoints().get_Width(), 122.0f, 0.25f);
ASSERT_NEAR(renderer->get_SizeInPoints().get_Height(), 13.0f, 0.15f);

ASSERT_NEAR(renderer->get_BoundsInPoints().get_Width(), 122.0f, 0.25f);
ASSERT_NEAR(renderer->get_BoundsInPoints().get_Height(), 13.0f, 0.15f);

// Shapes with transparent parts may contain different values in the "OpaqueBoundsInPoints" properties.
ASSERT_NEAR(renderer->get_OpaqueBoundsInPoints().get_Width(), 119.5f, 0.25f);
ASSERT_NEAR(renderer->get_OpaqueBoundsInPoints().get_Height(), 14.2f, 0.1f);

// Get the shape size in pixels, with linear scaling to a specific DPI.
System::Drawing::Rectangle bounds = renderer->GetBoundsInPixels(1.0f, 96.0f);
System::String dpi96 = u"DPI 96";
ASSERT_EQ(bounds.get_Width(), 163) << (dpi96);
ASSERT_EQ(bounds.get_Height(), 18) << (dpi96);

// Get the shape size in pixels, but with a different DPI for the horizontal and vertical dimensions.
bounds = renderer->GetBoundsInPixels(1.0f, 96.0f, 150.0f);
System::String dpi96150 = u"DPI 96 150";
ASSERT_EQ(bounds.get_Width(), 163) << (dpi96150);
ASSERT_EQ(bounds.get_Height(), 27) << (dpi96150);

// The opaque bounds may vary here also.
bounds = renderer->GetOpaqueBoundsInPixels(1.0f, 96.0f);
System::String dpi96Opaque = u"DPI 96 Opaque";
ASSERT_EQ(bounds.get_Width(), 160) << (dpi96Opaque);
ASSERT_EQ(bounds.get_Height(), 19) << (dpi96Opaque);

bounds = renderer->GetOpaqueBoundsInPixels(1.0f, 96.0f, 150.0f);
System::String dpi96150Opaque = u"DPI 96 150 Opaque";
ASSERT_EQ(bounds.get_Width(), 160) << (dpi96150Opaque);
ASSERT_EQ(bounds.get_Height(), 29) << (dpi96150Opaque);

See Also