diff --git a/Sources/CSkia/utils.cpp b/Sources/CSkia/utils.cpp index 3bae1a5..f36bcf7 100644 --- a/Sources/CSkia/utils.cpp +++ b/Sources/CSkia/utils.cpp @@ -18,16 +18,9 @@ auto fontMgr = SkFontMgr_New_DirectWrite(nullptr); auto fontMgr = SkFontMgr_New_FontConfig(nullptr); #endif -// The singleton font collection that will be used by all paragraph builders. -auto fontCollection1 = sk_make_sp(); - -ParagraphBuilder *paragraph_builder_new(ParagraphStyle &style) +ParagraphBuilder *paragraph_builder_new(ParagraphStyle &style, FontCollection_sp &fontCollection) { - // auto fontCollection1 = sk_make_sp(); - fontCollection1->setDefaultFontManager(fontMgr); - - auto result = ParagraphBuilder::make(style, fontCollection1); - // auto result = ParagraphBuilder::make(*style, font_collection); + auto result = ParagraphBuilder::make(style, fontCollection); auto result2 = result.release(); return result2; } diff --git a/Sources/CSkia/utils.h b/Sources/CSkia/utils.h index c1d7361..1724fcf 100644 --- a/Sources/CSkia/utils.h +++ b/Sources/CSkia/utils.h @@ -111,7 +111,7 @@ typedef sk_sp SkTextBlob_sp; // MARK: - ParagraphBuilder -ParagraphBuilder *paragraph_builder_new(ParagraphStyle &style); +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); diff --git a/Sources/Shaft/Backend/Skia/SkiaParagraph.swift b/Sources/Shaft/Backend/Skia/SkiaParagraph.swift index 0eddcc2..890b2fe 100644 --- a/Sources/Shaft/Backend/Skia/SkiaParagraph.swift +++ b/Sources/Shaft/Backend/Skia/SkiaParagraph.swift @@ -4,14 +4,11 @@ import CSkia -// let fontCollection = test_font_collection() - public class SkiaParagraphBuilder: ParagraphBuilder { - public required init(_ style: ParagraphStyle) { + public init(_ style: ParagraphStyle, fontCollection: SkiaFontCollection) { var skiaStyle = skia.textlayout.ParagraphStyle() style.copyToSkia(&skiaStyle) - // builder = paragraph_builder_new(&skiaStyle, fontCollection) - builder = paragraph_builder_new(&skiaStyle) + builder = paragraph_builder_new(&skiaStyle, &fontCollection.collection) } deinit { diff --git a/Sources/Shaft/Backend/Skia/SkiaRenderer.swift b/Sources/Shaft/Backend/Skia/SkiaRenderer.swift index 738f515..1039582 100644 --- a/Sources/Shaft/Backend/Skia/SkiaRenderer.swift +++ b/Sources/Shaft/Backend/Skia/SkiaRenderer.swift @@ -11,7 +11,7 @@ public class SkiaRenderer: Renderer { } public func createParagraphBuilder(_ style: ParagraphStyle) -> ParagraphBuilder { - SkiaParagraphBuilder(style) + SkiaParagraphBuilder(style, fontCollection: _fontCollection) } public func createTextBlob(_ glyphs: [GlyphID], positions: [Offset], font: any Font) @@ -28,5 +28,6 @@ public class SkiaRenderer: Renderer { SkiaPath() } - public let fontCollection: FontCollection = SkiaFontCollection() + public let _fontCollection = SkiaFontCollection() + public var fontCollection: FontCollection { _fontCollection } } diff --git a/Sources/Shaft/Core/TextTypes.swift b/Sources/Shaft/Core/TextTypes.swift index fb9cccf..8a7027a 100644 --- a/Sources/Shaft/Core/TextTypes.swift +++ b/Sources/Shaft/Core/TextTypes.swift @@ -918,8 +918,6 @@ public struct ParagraphStyle { } public protocol ParagraphBuilder: AnyObject { - init(_ style: ParagraphStyle) - /// Applies the given style to the added text until [pop] is called. /// /// See [pop] for details.