-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from SixLabors/text-bounding-boxes
Refactor text measure to measure actual bounding box
- Loading branch information
Showing
115 changed files
with
655 additions
and
648 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using ImageSharp; | ||
using SixLabors.Fonts; | ||
using SixLabors.Shapes.Temp; | ||
|
||
namespace DrawWithImageSharp | ||
{ | ||
public static class BoundingBoxes | ||
{ | ||
public static void Generate(string text, Font font) | ||
{ | ||
using (var img = new Image<Rgba32>(1000, 1000)) | ||
{ | ||
img.Fill(Rgba32.White); | ||
|
||
var box = TextMeasurer.MeasureBounds(text, new RendererOptions(font)); | ||
var data = TextBuilder.GenerateGlyphsWithBox(text, new RendererOptions(font)); | ||
|
||
var f = Rgba32.Fuchsia; | ||
f.A = 128; | ||
img.Fill(Rgba32.Black, data.paths); | ||
img.Draw(f, 1, data.boxes); | ||
img.Draw(Rgba32.Lime, 1, new SixLabors.Shapes.RectangularePolygon(box)); | ||
|
||
img.Save("Output/Boxed.png"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.