Skip to content

Commit

Permalink
[OGSMOD-3248] Move the ScriptInfo and WordBreakIndexList into interme…
Browse files Browse the repository at this point in the history
…diateInfo. (PixarAnimationStudios#679)

### Description of Change(s)
Move the ScriptInfo and WordBreakIndexList into intermediateInfo.

### Fixes Issue(s)
-

<!--
Please follow the Contributing and Building guidelines to run tests against your
change. Place an X in the box if tests are run and are all tests passing.
-->
- [ ] I have verified that all unit tests pass with the proposed changes
<!--
Place an X in the box if you have submitted a signed Contributor License Agreement.
A signed CLA must be received before pull requests can be merged.
For instructions, see: http://openusd.org/release/contributing_to_usd.html
-->
- [ ] I have submitted a signed Contributor License Agreement

(cherry picked from commit 5fe87842f8b9569ec9ddb29a752ce48b2491742d)
  • Loading branch information
PierreWang committed Nov 22, 2023
1 parent 3b2571a commit 4d5264c
Show file tree
Hide file tree
Showing 13 changed files with 460 additions and 150 deletions.
1 change: 1 addition & 0 deletions pxr/usdImaging/plugin/usdImagingCommonText/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pxr_plugin(usdImagingCommonText
CommonText/glyphOutline.cpp
CommonText/HT/contourSet.cpp
CommonText/HT/rankPolygon.cpp
CommonText/intermediateInfo.cpp
CommonText/languageAttribute.cpp
CommonText/Legacy/atom/atom_element_abandonment.cpp
CommonText/Legacy/atom/atom_element_environment.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ CommonTextTrueTypeGenericLayoutManager::_GenerateLayoutFromPreLayout()
}

// Initialize the line layout manager.
lineManager.Initialize(_genericText, _genericLayout, currentLineIter, currentLineLayoutIter, currentParagraphStyle,
lineManager.Initialize(_genericText, _genericLayout, _intermediateInfo,
currentLineIter, currentLineLayoutIter, currentParagraphStyle,
globalTextStyle, widthConstraint, heightConstraint - flowAccumulation);

if (line.LineType() == CommonTextLineType::CommonTextLineTypeZero)
Expand Down Expand Up @@ -421,8 +422,7 @@ CommonTextTrueTypeGenericLayoutManager::_GenerateLayoutFromPreLayout()
CommonTextLineList::iterator insertPos = currentLineIter;
++insertPos;
// Insert the newline
currentLineIter =
textLineList->insert(insertPos, std::move(newTextLine));
currentLineIter = AddTextLine(_genericText, _intermediateInfo, insertPos, newTextLine, WordBreakIndexList());
CommonTextLineLayoutList::iterator insertLayoutPos = currentLineLayoutIter;
++insertLayoutPos;
currentLineLayoutIter =
Expand Down Expand Up @@ -518,6 +518,8 @@ CommonTextTrueTypeGenericLayoutManager::GenerateGenericLayout()
{
if (_genericText)
{
_intermediateInfo = std::make_shared<CommonTextIntermediateInfo>(_genericText);

if (_genericText->State() == CommonTextGenericTextState::CommonTextGenericTextStatePreParse)
return CommonTextStatus::CommonTextStatusNotInitialized;

Expand Down Expand Up @@ -585,6 +587,7 @@ CommonTextTrueTypeGenericLayoutManager::_GenerateSimpleLayoutForAllRuns(
while (textRunIter != lastTextRun)
{
CommonTextRun& run = *textRunIter;
CommonTextRunInfo& textRunInfo = _intermediateInfo->GetTextRunInfo(textRunIter);
if (run.Type() == CommonTextRunType::CommonTextRunTypeString)
{
// If the textrun is string run, generate the layout using the simple manager.
Expand All @@ -610,7 +613,7 @@ CommonTextTrueTypeGenericLayoutManager::_GenerateSimpleLayoutForAllRuns(
std::wstring characters(markupString, run.StartIndex(), run.Length());
// Generate the metrics and indices for the characters.
CommonTextStatus status = simpleManager.GenerateSimpleLayout(
characters, textRunLayout, run.ComplexScriptInformation());
characters, textRunLayout, textRunInfo.ComplexScriptInformation());
if (status == CommonTextStatus::CommonTextStatusSuccess)
{
if (_useFullSizeToGenerateLayout)
Expand Down Expand Up @@ -642,7 +645,7 @@ CommonTextTrueTypeGenericLayoutManager::_GenerateSimpleLayoutForAllRuns(
// Get the subsitituted text runs after subsitituteFont.
CommonTextRunList::iterator lastRunIter = textRunIter;
CommonTextStatus substitutionStatus = pMultiLanguageHandler->SubstituteFont(
_genericText, textRunIter, textStyle, lineIter, textRunLayout, lastRunIter);
_genericText, _intermediateInfo, textRunIter, textStyle, lineIter, textRunLayout, lastRunIter);
if (substitutionStatus == CommonTextStatus::CommonTextStatusSuccess)
{
// Set the lastTextRun to the fontSubstitutionEndIter. In this way,
Expand Down Expand Up @@ -787,6 +790,7 @@ CommonTextTrueTypeGenericLayoutManager::GetAbsolutePositionForAllTextRuns(
CommonTextStatus
CommonTextTrueTypeGenericLayoutManager::_DivideTextRunByScripts(
std::shared_ptr<CommonTextGenericText> genericText,
std::shared_ptr<CommonTextIntermediateInfo> intermediateInfo,
CommonTextRunList::iterator textRunIter,
CommonTextLineList::iterator textLineIter,
CommonTextRunList::iterator& lastSubRunIter)
Expand All @@ -802,14 +806,16 @@ CommonTextTrueTypeGenericLayoutManager::_DivideTextRunByScripts(
return CommonTextStatus::CommonTextStatusSuccess;

CommonTextStatus divideStatus =
languageHandler->DivideStringByScripts(genericText, textRunIter, textLineIter, lastSubRunIter);
languageHandler->DivideStringByScripts(genericText, intermediateInfo,
textRunIter, textLineIter, lastSubRunIter);

return divideStatus;
}

CommonTextStatus
CommonTextTrueTypeGenericLayoutManager::_DivideTextRunByTabs(
std::shared_ptr<CommonTextGenericText> genericText,
std::shared_ptr<CommonTextIntermediateInfo> intermediateInfo,
CommonTextRunList::iterator textRunIter,
CommonTextLineList::iterator textLineIter,
CommonTextRunList::iterator& lastSubRunIter)
Expand Down Expand Up @@ -839,8 +845,8 @@ CommonTextTrueTypeGenericLayoutManager::_DivideTextRunByTabs(
}
if (dividePos.size() != 0)
{
CommonTextStatus status = DivideTextRun(genericText, textRunIter,
dividePos, textLineIter, lastSubRunIter);
CommonTextStatus status = DivideTextRun(genericText, intermediateInfo,
textRunIter, dividePos, textLineIter, lastSubRunIter);
if (status != CommonTextStatus::CommonTextStatusSuccess)
return status;
}
Expand All @@ -866,7 +872,8 @@ CommonTextTrueTypeGenericLayoutManager::_DivideTextRun(
{
CommonTextRunList::iterator lastRunIter = iter;
// Use divideFunc to do the dividing.
CommonTextStatus divideStatus = divideFunc(_genericText, iter, currentLineIter, lastRunIter);
CommonTextStatus divideStatus = divideFunc(_genericText, _intermediateInfo,
iter, currentLineIter, lastRunIter);
if (divideStatus != CommonTextStatus::CommonTextStatusSuccess)
return divideStatus;
iter = lastRunIter;
Expand Down Expand Up @@ -933,6 +940,7 @@ CommonTextTrueTypeGenericLayoutManager::CollectDecorations(
CommonTextStatus
CommonTextTrueTypeGenericLayoutManager::DivideTextRun(
std::shared_ptr<CommonTextGenericText> genericText,
std::shared_ptr<CommonTextIntermediateInfo> intermediateInfo,
CommonTextRunList::iterator textRunIter,
std::vector<int> dividePosInTextRun,
CommonTextLineList::iterator textLineIter,
Expand All @@ -952,6 +960,7 @@ CommonTextTrueTypeGenericLayoutManager::DivideTextRun(
dividePosInTextRun.push_back(fromRun.Length());

std::wstring characters(genericText->MarkupString(), textRunIter->StartIndex(), textRunIter->Length());
CommonTextRunInfo& textRunInfo = intermediateInfo->GetTextRunInfo(textRunIter);
std::shared_ptr<CommonTextRunList> listOfTextRuns = genericText->ListOfTextRuns();
CommonTextRunList::iterator subTextRunIter = textRunIter;
for (int index = 0; index < countOfSubRun; ++index)
Expand All @@ -964,10 +973,15 @@ CommonTextTrueTypeGenericLayoutManager::DivideTextRun(
// If the character is a tab, this is a tab run.
if (characters[dividePos] == '\t')
subTextRun.Type(CommonTextRunType::CommonTextRunTypeTab);
subTextRunIter = listOfTextRuns->insert_after(subTextRunIter, std::move(subTextRun));

CommonTextRunInfo subTextRunInfo;
subTextRunInfo.CopyPartOfData(textRunInfo, dividePos, nextPos - dividePos);

subTextRunIter = AddTextRun(genericText, intermediateInfo, subTextRunIter, subTextRun, subTextRunInfo);
}
// The original text run is shorten.
fromRun.Shorten(dividePosInTextRun[0]);
textRunInfo.Shorten(dividePosInTextRun[0]);
// If the character is a tab, this is a tab run.
if (characters[0] == '\t')
fromRun.Type(CommonTextRunType::CommonTextRunTypeTab);
Expand All @@ -979,5 +993,33 @@ CommonTextTrueTypeGenericLayoutManager::DivideTextRun(
}
return CommonTextStatus::CommonTextStatusSuccess;
}

CommonTextRunList::iterator
CommonTextTrueTypeGenericLayoutManager::AddTextRun(
std::shared_ptr<CommonTextGenericText> genericText,
std::shared_ptr<CommonTextIntermediateInfo> intermediateInfo,
CommonTextRunList::iterator insertPos,
const CommonTextRun& addedRun,
const CommonTextRunInfo& textRunInfo)
{
std::shared_ptr<CommonTextRunList> listOfTextRuns = genericText->ListOfTextRuns();
CommonTextRunList::iterator newRunIter = listOfTextRuns->insert_after(insertPos, addedRun);
intermediateInfo->_AddTextRunInfo(newRunIter, textRunInfo);
return newRunIter;
}

CommonTextLineList::iterator
CommonTextTrueTypeGenericLayoutManager::AddTextLine(
std::shared_ptr<CommonTextGenericText> genericText,
std::shared_ptr<CommonTextIntermediateInfo> intermediateInfo,
CommonTextLineList::iterator insertPos,
const CommonTextLine& addedLine,
const WordBreakIndexList& wordBreakIndexList)
{
std::shared_ptr<CommonTextLineList> listOfTextLines = genericText->ListOfTextLines();
CommonTextLineList::iterator newLineIter = listOfTextLines->insert(insertPos, addedLine);
intermediateInfo->_AddWordBreakIndexList(newLineIter, wordBreakIndexList);
return newLineIter;
}
} // namespace CommonText
PXR_NAMESPACE_CLOSE_SCOPE
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#define PXR_USD_IMAGING_PLUGIN_COMMON_TEXT_GENERIC_LAYOUT_H

#include "definitions.h"
#include "intermediateInfo.h"
#include "line.h"
#include "simpleLayout.h"

Expand All @@ -37,6 +38,7 @@ typedef std::list<CommonTextLine> CommonTextLineList;

typedef std::vector<std::pair<float, float>> CommonTextPosition2DArray;
typedef std::function<CommonTextStatus(std::shared_ptr<CommonTextGenericText>,
std::shared_ptr<CommonTextIntermediateInfo>,
CommonTextRunList::iterator,
CommonTextLineList::iterator,
CommonTextRunList::iterator&)> CommonTextDivideTextRunFunc;
Expand Down Expand Up @@ -368,6 +370,7 @@ class CommonTextTrueTypeGenericLayoutManager
_useFullSizeToGenerateLayout = useFullSizeToGenerateLayout;
_allowLineBreakInWord = allowLineBreakInWord;
_allowLineBreakBetweenScripts = allowLineBreakBetweenScripts;
_intermediateInfo = nullptr;
}

/// Parse the text.
Expand Down Expand Up @@ -400,11 +403,28 @@ class CommonTextTrueTypeGenericLayoutManager
/// Divide the textRun into a list of subTextRuns. The dividePosInTextRun is the
/// position that we divide the subTextRuns. The lastSubRunIter is the last subTextRun.
static CommonTextStatus DivideTextRun(std::shared_ptr<CommonTextGenericText> genericText,
std::shared_ptr<CommonTextIntermediateInfo> intermediateInfo,
CommonTextRunList::iterator textRunIter,
std::vector<int> dividePosInTextRun,
CommonTextLineList::iterator textLineIter,
CommonTextRunList::iterator& lastSubRunIter);

/// Add a TextRun into the genericText, and add its information to the intermediateInfo.
static CommonTextRunList::iterator AddTextRun(
std::shared_ptr<CommonTextGenericText> genericText,
std::shared_ptr<CommonTextIntermediateInfo> intermediateInfo,
CommonTextRunList::iterator insertPos,
const CommonTextRun& addedRun,
const CommonTextRunInfo& textRunInfo);

/// Add a TextLine into the genericText, and add its WordBreakIndexList to the intermediateInfo.
static CommonTextLineList::iterator AddTextLine(
std::shared_ptr<CommonTextGenericText> genericText,
std::shared_ptr<CommonTextIntermediateInfo> intermediateInfo,
CommonTextLineList::iterator insertPos,
const CommonTextLine& addedLine,
const WordBreakIndexList& wordBreakIndexList);

private:
/// Generate the layout from a CommonTextGenericText who is in pre-layout state.
CommonTextStatus _GenerateLayoutFromPreLayout();
Expand All @@ -428,12 +448,14 @@ class CommonTextTrueTypeGenericLayoutManager

/// Divide a text run if it is composed with different scripts.
static CommonTextStatus _DivideTextRunByScripts(std::shared_ptr<CommonTextGenericText> genericText,
std::shared_ptr<CommonTextIntermediateInfo> intermediateInfo,
CommonTextRunList::iterator textRunIter,
CommonTextLineList::iterator textLineIter,
CommonTextRunList::iterator& lastSubRunIter);

/// Divide a text run if it contains tabstops.
static CommonTextStatus _DivideTextRunByTabs(std::shared_ptr<CommonTextGenericText> genericText,
std::shared_ptr<CommonTextIntermediateInfo> intermediateInfo,
CommonTextRunList::iterator textRunIter,
CommonTextLineList::iterator textLineIter,
CommonTextRunList::iterator& lastSubRunIter);
Expand All @@ -450,6 +472,7 @@ class CommonTextTrueTypeGenericLayoutManager
CommonTextSystem* _textSystem = nullptr;
std::shared_ptr<CommonTextGenericText> _genericText = nullptr;
std::shared_ptr<CommonTextGenericLayout> _genericLayout = nullptr;
std::shared_ptr<CommonTextIntermediateInfo> _intermediateInfo = nullptr;
};
} // namespace CommonText
PXR_NAMESPACE_CLOSE_SCOPE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//
// Copyright 2023 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#include "intermediateInfo.h"

PXR_NAMESPACE_OPEN_SCOPE
namespace CommonText
{
CommonTextRunInfo CommonTextIntermediateInfo::_defaultTextRunInfo;
WordBreakIndexList CommonTextIntermediateInfo::_defaultWordBreakIndexList;
void
CommonTextRunInfo::CopyPartOfData(
const CommonTextRunInfo& fromInfo,
int startOffset,
int length)
{
// Copy the CommonTextScriptInfo.
CommonTextScriptInfo lastInfo;
for (auto info : fromInfo._scriptInfoArray)
{
if (info._indexOfFirstCharacter >= (int)startOffset &&
info._indexOfFirstCharacter < (int)(startOffset + length))
{
info._indexOfFirstCharacter -= startOffset;
if (_scriptInfoArray.size() == 0)
{
lastInfo._indexOfFirstCharacter = 0;
_scriptInfoArray.push_back(lastInfo);
}
_scriptInfoArray.push_back(info);
}
else
lastInfo = info;
}

// Copy the complex information.
if (fromInfo._complexScriptInfo != nullptr)
{
_complexScriptInfo =
std::make_shared<CommonTextComplexScriptInfo>(*(fromInfo._complexScriptInfo.get()));
}
}

CommonTextIntermediateInfo::CommonTextIntermediateInfo(std::shared_ptr<CommonTextGenericText> genericText)
{
const std::shared_ptr<CommonTextRunList> textRunList = genericText->ListOfTextRuns();
for (auto textRunIter = textRunList->begin(); textRunIter != textRunList->end(); ++textRunIter)
{
// For each TextRun, add a default information.
_AddTextRunInfo(textRunIter, CommonTextRunInfo());
}

const std::shared_ptr<CommonTextLineList> textLineList = genericText->ListOfTextLines();
for (auto textLineIter = textLineList->begin(); textLineIter != textLineList->end(); ++textLineIter)
{
// For each TextLine, add a default WordBreakIndexList.
_AddWordBreakIndexList(textLineIter, WordBreakIndexList());
}
}

} // namespace CommonText
PXR_NAMESPACE_CLOSE_SCOPE
Loading

0 comments on commit 4d5264c

Please sign in to comment.