Skip to content

Commit

Permalink
GlyphPage::fill() should take in a std::span
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=274341

Reviewed by Darin Adler.

* Source/WebCore/platform/graphics/Font.cpp:
(WebCore::fillGlyphPage):
(WebCore::createAndFillGlyphPage):
* Source/WebCore/platform/graphics/GlyphPage.h:
* Source/WebCore/platform/graphics/coretext/GlyphPageCoreText.cpp:
(WebCore::shouldFillWithVerticalGlyphs):
(WebCore::GlyphPage::fill):
* Source/WebCore/platform/graphics/freetype/GlyphPageTreeNodeFreeType.cpp:
(WebCore::GlyphPage::fill):
* Source/WebCore/platform/graphics/skia/GlyphPageSkia.cpp:
(WebCore::GlyphPage::fill):
* Source/WebCore/platform/graphics/win/GlyphPageTreeNodeWin.cpp:
(WebCore::GlyphPage::fill):

Canonical link: https://commits.webkit.org/278959@main
  • Loading branch information
cdumez committed May 18, 2024
1 parent 1ece8d0 commit 521e9dc
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions Source/WebCore/platform/graphics/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ RenderingResourceIdentifier FontInternalAttributes::ensureRenderingResourceIdent
return *renderingResourceIdentifier;
}

static bool fillGlyphPage(GlyphPage& pageToFill, UChar* buffer, unsigned bufferLength, const Font& font)
static bool fillGlyphPage(GlyphPage& pageToFill, std::span<const UChar> buffer, const Font& font)
{
bool hasGlyphs = pageToFill.fill(buffer, bufferLength);
bool hasGlyphs = pageToFill.fill(buffer);
#if ENABLE(OPENTYPE_VERTICAL)
if (hasGlyphs && font.verticalData())
font.verticalData()->substituteWithVerticalGlyphs(&font, &pageToFill);
Expand Down Expand Up @@ -400,7 +400,7 @@ static RefPtr<GlyphPage> createAndFillGlyphPage(unsigned pageNumber, const Font&
// for only 128 out of 256 characters.
Ref glyphPage = GlyphPage::create(font);

bool haveGlyphs = fillGlyphPage(glyphPage, buffer.data(), bufferLength, font);
bool haveGlyphs = fillGlyphPage(glyphPage, buffer.span().first(bufferLength), font);
if (!haveGlyphs)
return nullptr;

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/platform/graphics/GlyphPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class GlyphPage final : public RefCounted<GlyphPage> {
}

// Implemented by the platform.
bool fill(UChar* characterBuffer, unsigned bufferLength);
bool fill(std::span<const UChar> characterBuffer);

private:
explicit GlyphPage(const Font& font)
Expand Down
20 changes: 10 additions & 10 deletions Source/WebCore/platform/graphics/coretext/GlyphPageCoreText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,30 @@

namespace WebCore {

static bool shouldFillWithVerticalGlyphs(const UChar* buffer, unsigned bufferLength, const Font& font)
static bool shouldFillWithVerticalGlyphs(std::span<const UChar> buffer, const Font& font)
{
if (!font.hasVerticalGlyphs())
return false;
for (unsigned i = 0; i < bufferLength; ++i) {
if (!FontCascade::isCJKIdeograph(buffer[i]))
for (auto character : buffer) {
if (!FontCascade::isCJKIdeograph(character))
return true;
}
return false;
}


bool GlyphPage::fill(UChar* buffer, unsigned bufferLength)
bool GlyphPage::fill(std::span<const UChar> buffer)
{
ASSERT(bufferLength == GlyphPage::size || bufferLength == 2 * GlyphPage::size);
ASSERT(buffer.size() == GlyphPage::size || buffer.size() == 2 * GlyphPage::size);

const Font& font = this->font();
Vector<CGGlyph, 512> glyphs(bufferLength);
unsigned glyphStep = bufferLength / GlyphPage::size;
Vector<CGGlyph, 512> glyphs(buffer.size());
unsigned glyphStep = buffer.size() / GlyphPage::size;

if (shouldFillWithVerticalGlyphs(buffer, bufferLength, font))
CTFontGetVerticalGlyphsForCharacters(font.platformData().ctFont(), reinterpret_cast<UniChar*>(buffer), glyphs.data(), bufferLength);
if (shouldFillWithVerticalGlyphs(buffer, font))
CTFontGetVerticalGlyphsForCharacters(font.platformData().ctFont(), reinterpret_cast<const UniChar*>(buffer.data()), glyphs.data(), buffer.size());
else
CTFontGetGlyphsForCharacters(font.platformData().ctFont(), reinterpret_cast<UniChar*>(buffer), glyphs.data(), bufferLength);
CTFontGetGlyphsForCharacters(font.platformData().ctFont(), reinterpret_cast<const UniChar*>(buffer.data()), glyphs.data(), buffer.size());

bool haveGlyphs = false;
for (unsigned i = 0; i < GlyphPage::size; ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

namespace WebCore {

bool GlyphPage::fill(UChar* buffer, unsigned bufferLength)
bool GlyphPage::fill(std::span<const UChar> buffer)
{
const Font& font = this->font();
cairo_scaled_font_t* scaledFont = font.platformData().scaledFont();
Expand All @@ -63,10 +63,10 @@ bool GlyphPage::fill(UChar* buffer, unsigned bufferLength)
bool haveGlyphs = false;
unsigned bufferOffset = 0;
for (unsigned i = 0; i < GlyphPage::size; i++) {
if (bufferOffset == bufferLength)
if (bufferOffset == buffer.size())
break;
char32_t character;
U16_NEXT(buffer, bufferOffset, bufferLength, character);
U16_NEXT(buffer, bufferOffset, buffer.size(), character);

Glyph glyph = FcFreeTypeCharIndex(face, FontCascade::treatAsSpace(character) ? space : character);
// If the font doesn't support a Default_Ignorable character, replace it with zero with space.
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/platform/graphics/skia/GlyphPageSkia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@

namespace WebCore {

bool GlyphPage::fill(UChar* buffer, unsigned bufferLength)
bool GlyphPage::fill(std::span<const UChar> buffer)
{
const Font& font = this->font();
auto* skiaHarfBuzzFont = font.platformData().skiaHarfBuzzFont();
if (!skiaHarfBuzzFont)
return false;

StringView stringView(std::span(buffer, bufferLength));
StringView stringView(buffer);
auto codePoints = stringView.codePoints();
auto codePointsIterator = codePoints.begin();

Expand Down
12 changes: 6 additions & 6 deletions Source/WebCore/platform/graphics/win/GlyphPageTreeNodeWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@

namespace WebCore {

bool GlyphPage::fill(UChar* buffer, unsigned bufferLength)
bool GlyphPage::fill(std::span<const UChar> buffer)
{
ASSERT(bufferLength == GlyphPage::size || bufferLength == 2 * GlyphPage::size);
ASSERT(buffer.size() == GlyphPage::size || buffer.size() == 2 * GlyphPage::size);

const Font& font = this->font();
bool haveGlyphs = false;
Expand All @@ -47,10 +47,10 @@ bool GlyphPage::fill(UChar* buffer, unsigned bufferLength)
SelectObject(dc, font.platformData().hfont());

// FIXME: https://bugs.webkit.org/show_bug.cgi?id=259205 Determine if the glyph is a color glyph or not.
if (bufferLength == GlyphPage::size) {
if (buffer.size() == GlyphPage::size) {
WORD localGlyphBuffer[GlyphPage::size * 2];
DWORD result = GetGlyphIndices(dc, wcharFrom(buffer), bufferLength, localGlyphBuffer, GGI_MARK_NONEXISTING_GLYPHS);
bool success = result != GDI_ERROR && static_cast<unsigned>(result) == bufferLength;
DWORD result = GetGlyphIndices(dc, wcharFrom(buffer.data()), buffer.size(), localGlyphBuffer, GGI_MARK_NONEXISTING_GLYPHS);
bool success = result != GDI_ERROR && static_cast<unsigned>(result) == buffer.size();

if (success) {
for (unsigned i = 0; i < GlyphPage::size; i++) {
Expand All @@ -76,7 +76,7 @@ bool GlyphPage::fill(UChar* buffer, unsigned bufferLength)
gcpResults.lStructSize = sizeof gcpResults;
gcpResults.nGlyphs = 2;
gcpResults.lpGlyphs = glyphs;
GetCharacterPlacement(dc, wcharFrom(buffer) + i * 2, 2, 0, &gcpResults, GCP_GLYPHSHAPE);
GetCharacterPlacement(dc, wcharFrom(buffer.data()) + i * 2, 2, 0, &gcpResults, GCP_GLYPHSHAPE);
bool success = 1 == gcpResults.nGlyphs;
if (success) {
auto glyph = glyphs[0];
Expand Down

0 comments on commit 521e9dc

Please sign in to comment.