Sync changes from upstream repository

This commit is contained in:
Bozo the Builder
2023-11-15 14:18:19 -08:00
parent 92dfe19314
commit 5f656414c0
24 changed files with 878 additions and 293 deletions

View File

@@ -1133,19 +1133,15 @@ int ON_TextContent::Dimension() const
const ON_BoundingBox ON_TextContent::TextContentBoundingBox() const
{
ON_TextRunArray* runs = const_cast<ON_TextContent*>(this)->TextRuns(false);
const int run_count
= (nullptr != runs)
? runs->Count()
: 0;
const int run_count = (nullptr != runs) ? runs->Count() : 0;
if (run_count <= 0)
return ON_BoundingBox::EmptyBoundingBox;
const ON_SHA1_Hash text_content_hash = TextContentHash();
if (
m_text_content_bbox.IsValid()
&& m_text_content_bbox_hash == text_content_hash
)
// 28 Aug 2023 S. Baer
// Computing a content hash takes longer than just computing the bounding box
// for simple single run situations. Only use the cached bbox when there are
// more than one run.
if ( run_count > 1 &&
m_text_content_bbox.IsValid() &&
m_text_content_bbox_hash == TextContentHash())
{
return m_text_content_bbox;
}
@@ -1162,8 +1158,8 @@ const ON_BoundingBox ON_TextContent::TextContentBoundingBox() const
if (nullptr == run)
continue;
if (ON_TextRun::RunType::kText == (*runs)[i]->Type() ||
ON_TextRun::RunType::kField == (*runs)[i]->Type())
if (ON_TextRun::RunType::kText == run->Type() ||
ON_TextRun::RunType::kField == run->Type())
{
ON_BoundingBox runbox = run->BoundingBox();
if (false == runbox.IsValid())
@@ -1204,10 +1200,10 @@ const ON_BoundingBox ON_TextContent::TextContentBoundingBox() const
bbox.m_min.z = 0.0;
bbox.m_max.z = 0.0;
if (bbox.IsValid())
if (run_count>1 && bbox.IsValid())
{
m_text_content_bbox = bbox;
m_text_content_bbox_hash = text_content_hash;
m_text_content_bbox_hash = TextContentHash();
}
return bbox;