Skip to content

Commit

Permalink
Add some accessors to WidthIterator's internal iterators
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=260671
rdar://114400737

Reviewed by Cameron McCormack.

This is in preparation for removing the complex text codepath. These accessors will be
necessary when we actually make WidthIterator understand character clusters. For now,
they are unused.

No tests because there is no behavior change.

* Source/WebCore/platform/graphics/ComposedCharacterClusterTextIterator.h:
(WebCore::ComposedCharacterClusterTextIterator::remainingCharacters const):
(WebCore::ComposedCharacterClusterTextIterator::currentIndex const):
(WebCore::ComposedCharacterClusterTextIterator::characters const):
* Source/WebCore/platform/graphics/Latin1TextIterator.h:
(WebCore::Latin1TextIterator::remainingCharacters const):
* Source/WebCore/platform/graphics/SurrogatePairAwareTextIterator.h:
(WebCore::SurrogatePairAwareTextIterator::remainingCharacters const):
(WebCore::SurrogatePairAwareTextIterator::currentIndex const):
(WebCore::SurrogatePairAwareTextIterator::characters const):

Canonical link: https://commits.webkit.org/267254@main
  • Loading branch information
litherum committed Aug 25, 2023
1 parent 5dceefb commit 7f5ccd8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ class ComposedCharacterClusterTextIterator {
m_currentIndex += advanceLength;
}

unsigned currentIndex() const { return m_currentIndex; }

void reset(unsigned index)
{
ASSERT(index >= m_originalIndex);
Expand All @@ -73,12 +71,21 @@ class ComposedCharacterClusterTextIterator {
m_currentIndex = index;
}

const UChar* remainingCharacters() const
{
auto relativeIndex = m_currentIndex - m_originalIndex;
return m_characters + relativeIndex;
}

unsigned currentIndex() const { return m_currentIndex; }
const UChar* characters() const { return m_characters; }

private:
CachedTextBreakIterator m_iterator;
const UChar* m_characters;
unsigned m_originalIndex { 0 };
const UChar* const m_characters;
const unsigned m_originalIndex { 0 };
unsigned m_currentIndex { 0 };
unsigned m_lastIndex { 0 };
const unsigned m_lastIndex { 0 };
};

}
} // namespace WebCore
21 changes: 12 additions & 9 deletions Source/WebCore/platform/graphics/Latin1TextIterator.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2012 Apple Inc. All rights reserved.
* Copyright (C) 2012-2023 Apple Inc. All rights reserved.
* Copyright (C) Research In Motion Limited 2011. All rights reserved.
*
* This library is free software; you can redistribute it and/or
Expand All @@ -19,8 +19,7 @@
*
*/

#ifndef Latin1TextIterator_h
#define Latin1TextIterator_h
#pragma once

#include <wtf/text/WTFString.h>

Expand Down Expand Up @@ -61,16 +60,20 @@ class Latin1TextIterator {
m_currentIndex = index;
}

const LChar* remainingCharacters() const
{
auto relativeIndex = m_currentIndex - m_originalIndex;
return m_characters + relativeIndex;
}

unsigned currentIndex() const { return m_currentIndex; }
const LChar* characters() const { return m_characters; }

private:
const LChar* m_characters;
const LChar* const m_characters;
unsigned m_currentIndex;
unsigned m_originalIndex;
unsigned m_lastIndex;
const unsigned m_originalIndex;
const unsigned m_lastIndex;
};

}

#endif
} // namespace WebCore
21 changes: 14 additions & 7 deletions Source/WebCore/platform/graphics/SurrogatePairAwareTextIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,28 @@ class SurrogatePairAwareTextIterator {
m_currentIndex += advanceLength;
}

unsigned currentIndex() const { return m_currentIndex; }

void reset(unsigned index)
{
if (index >= m_lastIndex)
return;
m_currentIndex = index;
}

const UChar* remainingCharacters() const
{
auto relativeIndex = m_currentIndex - m_originalIndex;
return m_characters + relativeIndex;
}

unsigned currentIndex() const { return m_currentIndex; }
const UChar* characters() const { return m_characters; }

private:
const UChar* m_characters { nullptr };
const UChar* const m_characters { nullptr };
unsigned m_currentIndex { 0 };
unsigned m_originalIndex { 0 };
unsigned m_lastIndex { 0 };
unsigned m_endIndex { 0 };
const unsigned m_originalIndex { 0 };
const unsigned m_lastIndex { 0 };
const unsigned m_endIndex { 0 };
};

}
} // namespace WebCore

0 comments on commit 7f5ccd8

Please sign in to comment.