Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add support for interior polygons #1

Merged
merged 3 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 48 additions & 49 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ For now, see the [tests](tests/test_extrusion.rs). More examples coming soon!

## Limitations

* Currently supports only stencil fonts
* Right now all regions returned are exterior regions. Any glyphs with interiors will fail to extrude. Since stencil fonts have no interiors, they work well.
* Rendering using Fornjot is slow - try exporting to an STL and viewing in another viewer.
* Unlikely to support fonts with nested features (like a zero with a dot in the center).
* Rendering using Fornjot is slow - try exporting to an STL/OBJ/3MF and viewing in another viewer.
* All glyphs are individually normalized to a height of 1 - this should be changed, but I need to learn more about fonts first.

## Future

* Support for interior polygons
* Support string generation (currently only single glyph at a time)
* Reduce number of vertices used

Expand Down
20 changes: 17 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
use anyhow::{anyhow, Result};
use bezier_rs::{Bezier, TValueType};
use fj::core::{objects::Region, operations::build::BuildRegion, services::Services};
use fj::{
core::{
objects::Region,
operations::{build::BuildRegion, update::UpdateRegion},
services::Services,
},
math::Winding,
};
use font::{glyph::Segment, Font, Glyph, Offset};

const DEFAULT_RESOLUTION: usize = 5;
Expand Down Expand Up @@ -82,10 +89,17 @@ impl GlyphRegionBuilder {
.collect()
})
.collect();
let mut polygons = vec![];
let mut polygons: Vec<Region> = vec![];
for mut region_points in point_lists {
region_points.reverse();
polygons.push(Region::polygon(region_points, services));
let region = Region::polygon(region_points, services);
if region.exterior().winding() == Winding::Cw {
let last_polygon = polygons.remove(0);
let new_region = last_polygon.add_interiors([region.exterior().clone()]);
polygons.insert(0, new_region);
} else {
polygons.push(region);
}
}
polygons
}
Expand Down
Binary file added tests/fonts/NotoSans/NotoSans-Regular.ttf
Binary file not shown.
Loading