Skip to content

Commit

Permalink
Switch to use enum class for typesetterOptions() template in ComplexT…
Browse files Browse the repository at this point in the history
…extControllerCoreText.mm

https://bugs.webkit.org/show_bug.cgi?id=273109
<rdar://126898039>

Reviewed by Darin Adler.

* Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm:
(WebCore::CoreTextTypesetterEmbeddingLevel): Add enum.
(WebCore::buildCoreTextTypesetterEmbeddingLevelDictionary): Add.
- Extract common code out of typesetterOptions().
(WebCore::typesetterOptions):
- Call buildCoreTextTypesetterEmbeddingLevelDictionary().
(WebCore::ComplexTextController::collectComplexTextRunsForCharacters):
- Switch from bool value to CoreTextTypesetterEmbeddingLevel enum.

Canonical link: https://commits.webkit.org/278294@main
  • Loading branch information
David Kilzer authored and ddkilzer committed May 3, 2024
1 parent afc7f08 commit c277969
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,24 @@
return reinterpret_cast<const UniChar*>(info->cp.data() + stringIndex);
}

template<bool isLTR>
enum class CoreTextTypesetterEmbeddingLevel : short { LTR = 0, RTL = 1 };

NEVER_INLINE static RetainPtr<CFDictionaryRef> buildCoreTextTypesetterEmbeddingLevelDictionary(CoreTextTypesetterEmbeddingLevel embeddingLevel)
{
auto embeddingLevelValue = enumToUnderlyingType(embeddingLevel);
static_assert(std::is_same_v<short, decltype(embeddingLevelValue)>);
const void* optionKeys[] = { kCTTypesetterOptionForcedEmbeddingLevel };
const void* optionValues[] = { CFNumberCreate(kCFAllocatorDefault, kCFNumberShortType, &embeddingLevelValue) };
return adoptCF(CFDictionaryCreate(kCFAllocatorDefault, optionKeys, optionValues, std::size(optionKeys), &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
}

template<CoreTextTypesetterEmbeddingLevel embeddingLevel>
static CFDictionaryRef typesetterOptions()
{
static LazyNeverDestroyed<RetainPtr<CFDictionaryRef>> options;
static std::once_flag onceFlag;
std::call_once(onceFlag, [&] {
short embeddingLevelValue = isLTR ? 0 : 1;
const void* optionKeys[] = { kCTTypesetterOptionForcedEmbeddingLevel };
const void* optionValues[] = { CFNumberCreate(kCFAllocatorDefault, kCFNumberShortType, &embeddingLevelValue) };
options.construct(adoptCF(CFDictionaryCreate(kCFAllocatorDefault, optionKeys, optionValues, std::size(optionKeys), &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)));
options.construct(buildCoreTextTypesetterEmbeddingLevelDictionary(embeddingLevel));
});
return options.get().get();
}
Expand Down Expand Up @@ -188,7 +196,7 @@ static CFDictionaryRef typesetterOptions()
ProviderInfo info { cp, stringAttributes.get() };
// FIXME: Some SDKs complain that the second parameter below cannot be null.
IGNORE_NULL_CHECK_WARNINGS_BEGIN
auto typesetter = adoptCF(CTTypesetterCreateWithUniCharProviderAndOptions(&provideStringAndAttributes, 0, &info, m_run.ltr() ? typesetterOptions<true>() : typesetterOptions<false>()));
auto typesetter = adoptCF(CTTypesetterCreateWithUniCharProviderAndOptions(&provideStringAndAttributes, 0, &info, m_run.ltr() ? typesetterOptions<CoreTextTypesetterEmbeddingLevel::LTR>() : typesetterOptions<CoreTextTypesetterEmbeddingLevel::RTL>()));
IGNORE_NULL_CHECK_WARNINGS_END

if (!typesetter)
Expand Down

0 comments on commit c277969

Please sign in to comment.