diff --git a/Sources/CSkia/utils.cpp b/Sources/CSkia/utils.cpp index f36bcf7..33cd75e 100644 --- a/Sources/CSkia/utils.cpp +++ b/Sources/CSkia/utils.cpp @@ -18,39 +18,31 @@ auto fontMgr = SkFontMgr_New_DirectWrite(nullptr); auto fontMgr = SkFontMgr_New_FontConfig(nullptr); #endif -ParagraphBuilder *paragraph_builder_new(ParagraphStyle &style, FontCollection_sp &fontCollection) +ParagraphBuilder_up paragraph_builder_new(ParagraphStyle &style, FontCollection_sp &fontCollection) { - auto result = ParagraphBuilder::make(style, fontCollection); - auto result2 = result.release(); - return result2; + return ParagraphBuilder::make(style, fontCollection); } -void paragraph_builder_add_text(ParagraphBuilder *builder, const char *text) +void paragraph_builder_add_text(const ParagraphBuilder_up &builder, const char *text) { builder->addText(text); - // builder->addText(text, strlen(text)); } -void paragraph_builder_push_style(ParagraphBuilder *builder, const TextStyle *style) +void paragraph_builder_push_style(const ParagraphBuilder_up &builder, const TextStyle *style) { builder->pushStyle(*style); } -void paragraph_builder_pop(ParagraphBuilder *builder) +void paragraph_builder_pop(const ParagraphBuilder_up &builder) { builder->pop(); } -Paragraph *paragraph_builder_build(ParagraphBuilder *builder) +Paragraph *paragraph_builder_build(const ParagraphBuilder_up &builder) { return builder->Build().release(); } -void paragraph_builder_unref(ParagraphBuilder *builder) -{ - std::default_delete()(builder); -} - // MARK: - Paragraph std::vector paragraph_get_fonts(Paragraph *paragraph) diff --git a/Sources/CSkia/utils.h b/Sources/CSkia/utils.h index 1724fcf..e3061ae 100644 --- a/Sources/CSkia/utils.h +++ b/Sources/CSkia/utils.h @@ -106,17 +106,17 @@ typedef sk_sp FontCollection_sp; typedef sk_sp ParagraphBuilder_sp; typedef sk_sp SkTypeface_sp; typedef sk_sp SkTextBlob_sp; +typedef std::unique_ptr ParagraphBuilder_up; // FontCollection_sp test_font_collection(); // MARK: - ParagraphBuilder -ParagraphBuilder *paragraph_builder_new(ParagraphStyle &style, FontCollection_sp &fontCollection); -void paragraph_builder_add_text(ParagraphBuilder *builder, const char *text); -void paragraph_builder_push_style(ParagraphBuilder *builder, const TextStyle *style); -void paragraph_builder_pop(ParagraphBuilder *builder); -Paragraph *paragraph_builder_build(ParagraphBuilder *builder); -void paragraph_builder_unref(ParagraphBuilder *builder); +ParagraphBuilder_up paragraph_builder_new(ParagraphStyle &style, FontCollection_sp &fontCollection); +void paragraph_builder_add_text(const ParagraphBuilder_up &builder, const char *text); +void paragraph_builder_push_style(const ParagraphBuilder_up &builder, const TextStyle *style); +void paragraph_builder_pop(const ParagraphBuilder_up &builder); +Paragraph *paragraph_builder_build(const ParagraphBuilder_up &builder); // MARK: - Paragraph diff --git a/Sources/Shaft/Backend/Skia/SkiaParagraph.swift b/Sources/Shaft/Backend/Skia/SkiaParagraph.swift index 890b2fe..0c754e7 100644 --- a/Sources/Shaft/Backend/Skia/SkiaParagraph.swift +++ b/Sources/Shaft/Backend/Skia/SkiaParagraph.swift @@ -11,11 +11,7 @@ public class SkiaParagraphBuilder: ParagraphBuilder { builder = paragraph_builder_new(&skiaStyle, &fontCollection.collection) } - deinit { - paragraph_builder_unref(builder) - } - - public let builder: UnsafeMutablePointer + public let builder: ParagraphBuilder_up public func pushStyle(_ style: SpanStyle) { var skiaStyle = skia.textlayout.TextStyle()