src/lib/CDRCollector.cpp        |   25 +++++---------
 src/lib/CDRContentCollector.cpp |   70 +++++++++++++---------------------------
 2 files changed, 33 insertions(+), 62 deletions(-)

New commits:
commit b5211a57af37dac59a04f6041822a07f4a7cf7d6
Author:     Caolán McNamara <[email protected]>
AuthorDate: Mon Nov 23 10:44:22 2026 +0000
Commit:     Caolán McNamara <[email protected]>
CommitDate: Mon Nov 23 10:47:31 2026 +0000

    draw a pattern fill only if the pattern has data for its whole size
    
    and work out the bitmap size in 64 bits
    
    since:
    
    commit da4f0e48db2e24a2327975d955015190a1bfdd3d
    Date:   Thu Mar 1 16:33:31 2012 +0100
    
        Trying to support the proper pattern fill
    
    Change-Id: I6a7c46c7359dc7c09651e2f4d31855f0fa32cca6

diff --git a/src/lib/CDRContentCollector.cpp b/src/lib/CDRContentCollector.cpp
index 946625c..7c13585 100644
--- a/src/lib/CDRContentCollector.cpp
+++ b/src/lib/CDRContentCollector.cpp
@@ -11,6 +11,7 @@
 
 #include <cmath>
 #include <cstdint>
+#include <limits>
 #include <string>
 #include <utility>
 
@@ -1535,20 +1536,19 @@ const librevenge::RVNGString 
&libcdr::CDRContentCollector::_markerPath(const std
 
 void 
libcdr::CDRContentCollector::_generateBitmapFromPattern(librevenge::RVNGBinaryData
 &bitmap, const CDRPattern &pattern, const CDRColor &fgColor, const CDRColor 
&bgColor)
 {
-  unsigned height = pattern.height;
-  unsigned width = pattern.width;
-  auto tmpPixelSize = (unsigned)(height * width);
-  if (tmpPixelSize < (unsigned)height) // overflow
+  const unsigned height = pattern.height;
+  const unsigned width = pattern.width;
+  // The pattern has one bit per pixel, and each row starts on a new byte.
+  const uint64_t lineWidth = (uint64_t(width) + 7) / 8;
+  if (height * lineWidth > pattern.pattern.size())
     return;
 
-  unsigned tmpDIBImageSize = tmpPixelSize * 4;
-  if (tmpPixelSize > tmpDIBImageSize) // overflow !!!
-    return;
-
-  unsigned tmpDIBOffsetBits = 14 + 40;
-  unsigned tmpDIBFileSize = tmpDIBOffsetBits + tmpDIBImageSize;
-  if (tmpDIBImageSize > tmpDIBFileSize) // overflow !!!
+  const unsigned tmpDIBOffsetBits = 14 + 40;
+  const uint64_t pixelCount = uint64_t(height) * width;
+  if (pixelCount > (std::numeric_limits<unsigned>::max() - tmpDIBOffsetBits) / 
4)
     return;
+  const auto tmpDIBImageSize = unsigned(pixelCount * 4);
+  const unsigned tmpDIBFileSize = tmpDIBOffsetBits + tmpDIBImageSize;
 
   // Create DIB file header
   writeU16(bitmap, 0x4D42);  // Type
@@ -1572,9 +1572,6 @@ void 
libcdr::CDRContentCollector::_generateBitmapFromPattern(librevenge::RVNGBin
   writeU32(bitmap, 0); // ColorsUsed
   writeU32(bitmap, 0); // ColorsImportant
 
-  // The Bitmaps in CDR are padded to 32bit border
-  unsigned lineWidth = (width + 7) / 8;
-
   unsigned foreground = m_ps._getRGBColor(fgColor);
   unsigned background = m_ps._getRGBColor(bgColor);
 
@@ -1585,10 +1582,7 @@ void 
libcdr::CDRContentCollector::_generateBitmapFromPattern(librevenge::RVNGBin
     while (i <lineWidth && k < width)
     {
       unsigned l = 0;
-      unsigned char c = 0;
-      const unsigned index = (j-1)*lineWidth+i;
-      if (index < pattern.pattern.size())
-        c = pattern.pattern[index];
+      unsigned char c = pattern.pattern[(j-1)*lineWidth+i];
       i++;
       while (k < width && l < 8)
       {
commit a5e391ed3f26510564d8229775f1324f0d00a062
Author:     Caolán McNamara <[email protected]>
AuthorDate: Mon Nov 23 10:43:31 2026 +0000
Commit:     Caolán McNamara <[email protected]>
CommitDate: Mon Nov 23 10:43:31 2026 +0000

    normalize every bitmap and full colour fill offset
    
    as the pattern fill offsets already are, and give 0 for an offset that
    is not a finite number
    
    since:
    
    commit a4b4aef37c843a07f867c26d22f5a4b5a25deba0
    Date:   Fri Mar 16 13:53:13 2012 +0100
    
        Some bitmap fill fixes
    
    Change-Id: I4db0c58e8c5d251dbffbb4a5c2020b63d1024042

diff --git a/src/lib/CDRContentCollector.cpp b/src/lib/CDRContentCollector.cpp
index bac44e2..946625c 100644
--- a/src/lib/CDRContentCollector.cpp
+++ b/src/lib/CDRContentCollector.cpp
@@ -9,6 +9,7 @@
 
 #include "CDRContentCollector.h"
 
+#include <cmath>
 #include <cstdint>
 #include <string>
 #include <utility>
@@ -70,22 +71,15 @@ librevenge::RVNGString markerPath(const libcdr::CDRPath 
&marker)
 /// Move the number into [0;1] range.
 void normalize(double &d)
 {
-  if (d < 0.0)
+  if (!std::isfinite(d))
   {
-    const double n = d + static_cast<unsigned long>(-d) + 1.0;
-    if ((n < 0.0) || (n > 1.0))
-      d = 0.0; // The number was too big, thus rounded. Just pick a value.
-    else
-      d = n;
+    d = 0.0;
+    return;
   }
+  if (d < 0.0)
+    d += std::floor(-d) + 1.0;
   if (d > 1.0)
-  {
-    const double n = d - static_cast<unsigned long>(d);
-    if ((n < 0.0) || (n > 1.0))
-      d = 0.0; // The number was too big, thus rounded. Just pick a value.
-    else
-      d = n;
-  }
+    d -= std::floor(d);
 }
 
 void normalizeAngle(double &angle)
@@ -1274,19 +1268,13 @@ void 
libcdr::CDRContentCollector::_fillProperties(librevenge::RVNGPropertyList &
             if (!CDR_ALMOST_ZERO(m_fillTransforms.getTranslateX()))
             {
               double xOffset = m_fillTransforms.getTranslateX() / 
m_currentFillStyle.imageFill.width;
-              while (xOffset < 0.0)
-                xOffset += 1.0;
-              while (xOffset > 1.0)
-                xOffset -= 1.0;
+              normalize(xOffset);
               propList.insert("draw:fill-image-ref-point-x", xOffset, 
librevenge::RVNG_PERCENT);
             }
             if (!CDR_ALMOST_ZERO(m_fillTransforms.getTranslateY()))
             {
               double yOffset = m_fillTransforms.getTranslateY() / 
m_currentFillStyle.imageFill.height;
-              while (yOffset < 0.0)
-                yOffset += 1.0;
-              while (yOffset > 1.0)
-                yOffset -= 1.0;
+              normalize(yOffset);
               propList.insert("draw:fill-image-ref-point-y", 1.0 - yOffset, 
librevenge::RVNG_PERCENT);
             }
           }
@@ -1339,19 +1327,13 @@ void 
libcdr::CDRContentCollector::_fillProperties(librevenge::RVNGPropertyList &
             if (!CDR_ALMOST_ZERO(m_fillTransforms.getTranslateX()))
             {
               double xOffset = m_fillTransforms.getTranslateX() / 
m_currentFillStyle.imageFill.width;
-              while (xOffset < 0.0)
-                xOffset += 1.0;
-              while (xOffset > 1.0)
-                xOffset -= 1.0;
+              normalize(xOffset);
               propList.insert("draw:fill-image-ref-point-x", xOffset, 
librevenge::RVNG_PERCENT);
             }
             if (!CDR_ALMOST_ZERO(m_fillTransforms.getTranslateY()))
             {
               double yOffset = m_fillTransforms.getTranslateY() / 
m_currentFillStyle.imageFill.height;
-              while (yOffset < 0.0)
-                yOffset += 1.0;
-              while (yOffset > 1.0)
-                yOffset -= 1.0;
+              normalize(yOffset);
               propList.insert("draw:fill-image-ref-point-y", 1.0 - yOffset, 
librevenge::RVNG_PERCENT);
             }
           }
commit 0fd1e8a4a5c3f934802794a7b0cd12baaa2a7b6c
Author:     Caolán McNamara <[email protected]>
AuthorDate: Mon Nov 23 10:43:07 2026 +0000
Commit:     Caolán McNamara <[email protected]>
CommitDate: Mon Nov 23 10:43:07 2026 +0000

    stop following a style's parents at one already visited
    
    since:
    
    commit ce2c827e57851f8f81b349ac6905e0f02775be53
    Date:   Wed Apr 10 21:32:08 2013 +0200
    
        Refactoring of text-related stuff
    
    Change-Id: I84791505830c276586947e4ae6a9385ae9878ef4

diff --git a/src/lib/CDRCollector.cpp b/src/lib/CDRCollector.cpp
index 43e6299..a0a1311 100644
--- a/src/lib/CDRCollector.cpp
+++ b/src/lib/CDRCollector.cpp
@@ -592,23 +592,18 @@ librevenge::RVNGString 
libcdr::CDRParserState::getRGBColorString(const libcdr::C
 
 void libcdr::CDRParserState::getRecursedStyle(CDRStyle &style, unsigned 
styleId)
 {
-  std::map<unsigned, CDRStyle>::const_iterator iter = m_styles.find(styleId);
-  if (iter == m_styles.end())
-    return;
-
   std::stack<CDRStyle> styleStack;
-  styleStack.push(iter->second);
-  if (iter->second.m_parentId)
+  std::set<unsigned> visitedIds;
+  unsigned id = styleId;
+  while (visitedIds.insert(id).second)
   {
-    std::map<unsigned, CDRStyle>::const_iterator iter2 = 
m_styles.find(iter->second.m_parentId);
-    while (iter2 != m_styles.end())
-    {
-      styleStack.push(iter2->second);
-      if (iter2->second.m_parentId)
-        iter2 = m_styles.find(iter2->second.m_parentId);
-      else
-        iter2 = m_styles.end();
-    }
+    const auto iter = m_styles.find(id);
+    if (iter == m_styles.end())
+      break;
+    styleStack.push(iter->second);
+    if (!iter->second.m_parentId)
+      break;
+    id = iter->second.m_parentId;
   }
   while (!styleStack.empty())
   {

Reply via email to