Skip to content

Commit

Permalink
(#63) Docs: add XML documentation and refresh the README
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR committed Jan 19, 2023
1 parent fdd7b54 commit 01617cd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
44 changes: 18 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,43 +49,35 @@ namespace ConsoleApplication2
}
```

If you need any additional control over the image format, consider using the `GetRenderer` API:
If you need any additional control over the image format, consider using the extension methods from the `WpfTeXFormulaExtensions` class:

```csharp
using System;
using System.IO;
using System.Windows.Media.Imaging;
using WpfMath;
using WpfMath.Rendering;

namespace ConsoleApplication2
{
internal class Program
{
public static void Main(string[] args)
{
const string latex = @"\frac{2+2}{2}";
const string fileName = @"T:\Temp\formula.png";
const string latex = @"\frac{2+2}{2}";
const string fileName = @"T:\Temp\formula.png";

var parser = new TexFormulaParser();
var formula = parser.Parse(latex);
var renderer = formula.GetRenderer(TexStyle.Display, 20.0, "Arial");
var bitmapSource = renderer.RenderToBitmap(0.0, 0.0);
Console.WriteLine($"Image width: {bitmapSource.Width}");
Console.WriteLine($"Image height: {bitmapSource.Height}");

var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bitmapSource));
using (var target = new FileStream(fileName, FileMode.Create))
{
encoder.Save(target);
Console.WriteLine($"File saved to {fileName}");
}
}
}
var parser = new TexFormulaParser();
var formula = parser.Parse(latex);
var environment = WpfTeXEnvironment.Create(TexStyle.Display, 20.0, "Arial");
var bitmapSource = formula.RenderToBitmap(environment);
Console.WriteLine($"Image width: {bitmapSource.Width}");
Console.WriteLine($"Image height: {bitmapSource.Height}");

var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bitmapSource));
using (var target = new FileStream(fileName, FileMode.Create))
{
encoder.Save(target);
Console.WriteLine($"File saved to {fileName}");
}
```

You may also pass your own `IElementRenderer` implementation to `TexFormula.RenderFormulaTo` method if you need support for any alternate rendering engines.
You may also pass your own `IElementRenderer` implementation to `TeXFormulaExtensions::RenderTo` method if you need support for any alternate rendering engines.

Documentation
-------------
Expand Down
5 changes: 5 additions & 0 deletions src/WpfMath/Rendering/WpfTeXFormulaExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public static Geometry RenderToGeometry(
}

/// <summary>Renders the formula to a WPF bitmap.</summary>
/// <param name="formula">The formula to render.</param>
/// <param name="environment">The environment with rendering parameters.</param>
/// <param name="scale">Formula text scale./</param>
/// <param name="x">A physical X coordinate of the top left corner in the resulting bitmap.</param>
/// <param name="y">A physical Y coordinate of the top left corner in the resulting bitmap.</param>
Expand Down Expand Up @@ -72,6 +74,9 @@ private static void RenderWithPositiveCoordinates(
/// <summary>
/// Renders the <paramref name="formula"/> to the <paramref name="drawingContext"/>.
/// </summary>
/// <param name="formula">The formula to render.</param>
/// <param name="drawingContext">The target drawing context.</param>
/// <param name="environment">The environment with rendering parameters.</param>
/// <param name="scale">Formula text scale./</param>
/// <param name="x">Logical X coordinate of the top left corner of the formula.</param>
/// <param name="y">Logical Y coordinate of the top left corner of the formula.</param>
Expand Down

0 comments on commit 01617cd

Please sign in to comment.