Skip to content

Commit

Permalink
Text support
Browse files Browse the repository at this point in the history
  • Loading branch information
cartesian-theatrics committed Mar 31, 2024
1 parent fceda91 commit 798d1cf
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ write_basic_package_version_file(
VERSION ${MANIFOLD_VERSION}
COMPATIBILITY SameMajorVersion
)

target_link_libraries(cross_section PUBLIC TextToPolygon)

install(EXPORT manifoldTargets DESTINATION ${CMAKE_INSTALL_DATADIR}/manifold)
configure_file(manifoldConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/manifoldConfig.cmake @ONLY)
install(FILES
Expand Down
18 changes: 18 additions & 0 deletions manifoldDeps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@ else()
endif()
endif()

FetchContent_Declare(
TextToPolygon
GIT_REPOSITORY https://github.com/SovereignShop/text-to-polygon.git
GIT_TAG 670e4a71ba3dd1de2f7edcf73f748ab4eeec3828
)
FetchContent_MakeAvailable(TextToPolygon)

target_link_libraries(TextToPolygon
PRIVATE
freetype
)

target_include_directories(TextToPolygon PUBLIC
$<BUILD_INTERFACE:${texttopolygon_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)


FetchContent_Declare(glm
GIT_REPOSITORY https://github.com/g-truc/glm.git
GIT_TAG b06b775c1c80af51a1183c0e167f9de3b2351a79
Expand Down
2 changes: 2 additions & 0 deletions src/cross_section/include/cross_section.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <functional>
#include <memory>
#include <vector>
#include "text_to_polygon.h"

#include "glm/ext/matrix_float3x2.hpp"
#include "glm/ext/vector_float2.hpp"
Expand Down Expand Up @@ -74,6 +75,7 @@ class CrossSection {
CrossSection(const Polygons& contours,
FillRule fillrule = FillRule::Positive);
CrossSection(const Rect& rect);
static CrossSection Text(const std::string& fontFile, const std::string& text, u_int32_t pixelHeight, int interpRes);
static CrossSection Square(const glm::vec2 dims, bool center = false);
static CrossSection Circle(float radius, int circularSegments = 0);
///@}
Expand Down
14 changes: 14 additions & 0 deletions src/cross_section/src/cross_section.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include "cross_section.h"
#include "text_to_polygon.h"

#include "clipper2/clipper.core.h"
#include "clipper2/clipper.h"
Expand Down Expand Up @@ -304,6 +305,19 @@ std::shared_ptr<const PathImpl> CrossSection::GetPaths() const {
return paths_;
}

/**
* Renders text to a cross section.
*
* @param fontFile path to a .ttf font file.
* @param text Text to render as polygon
* @param pixelHeight freetype pixelHeight.
* @param interpRes Resolution of interpolation of curves.
*/
CrossSection CrossSection::Text(const std::string& fontFile, const std::string& text, u_int32_t pixelHeight, int interpRes) {
Polygons polys = TextToPolygon::textToPolygons(fontFile, text, pixelHeight, interpRes);
return CrossSection(polys, FillRule::NonZero);
}

/**
* Constructs a square with the given XY dimensions. By default it is
* positioned in the first quadrant, touching the origin. If any dimensions in
Expand Down

0 comments on commit 798d1cf

Please sign in to comment.