[Libreoffice-commits] core.git: 2 commits - include/svx include/vcl svx/qa svx/source vcl/source
GülÅah Köse (via logerrit)
logerrit at kemper.freedesktop.org
Fri Oct 16 10:05:34 UTC 2020
include/svx/svdoashp.hxx | 1
include/svx/svdotext.hxx | 1
include/vcl/filter/PDFiumLibrary.hxx | 2
svx/qa/unit/customshapes.cxx | 2
svx/source/sdr/contact/viewcontactofsdrobjcustomshape.cxx | 21 +-------
svx/source/svdraw/svdoashp.cxx | 16 ------
svx/source/svdraw/svdotextdecomposition.cxx | 35 ++++++++++++++
vcl/source/filter/ipdf/pdfread.cxx | 31 ++++++------
vcl/source/pdf/PDFiumLibrary.cxx | 26 ++++++++--
9 files changed, 80 insertions(+), 55 deletions(-)
New commits:
commit c7ada1cc8a294f0d2da32ffc02d0941b1b1afd29
Author: Gülşah Köse <gulsah.kose at collabora.com>
AuthorDate: Mon Oct 5 14:57:33 2020 +0300
Commit: Gülşah Köse <gulsah.kose at collabora.com>
CommitDate: Fri Oct 16 12:05:02 2020 +0200
tdf#128212 Change the text z camera rotation order.
Old order:
1) Apply all rotation values (normal and camera z)
2) Do the adjustment (top, middle, bottom)
New Order:
1) Apply rotation values except camera z
2) Do the adjustment (top, middle, bottom)
3) Apply camera z rotation.
We rotate the text at the center of the already positioned rectangle
of the text, which depends on e.g. the length of the laid out text.
This matches the PowerPoint behavior.
Change-Id: I8741cf443834bf01cc07c04318fd6205ed6a0dd6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103965
Tested-by: Jenkins
Reviewed-by: Gülşah Köse <gulsah.kose at collabora.com>
diff --git a/include/svx/svdoashp.hxx b/include/svx/svdoashp.hxx
index 535060caf5ca..dd1a86d24bca 100644
--- a/include/svx/svdoashp.hxx
+++ b/include/svx/svdoashp.hxx
@@ -142,7 +142,6 @@ public:
double GetObjectRotation() const { return fObjectRotation;}
double GetExtraTextRotation( const bool bPreRotation = false ) const;
- double GetCameraRotation() const;
SdrObjCustomShape(SdrModel& rSdrModel);
diff --git a/include/svx/svdotext.hxx b/include/svx/svdotext.hxx
index 1de1b3edd89c..fd69b4a681b7 100644
--- a/include/svx/svdotext.hxx
+++ b/include/svx/svdotext.hxx
@@ -577,6 +577,7 @@ public:
// Set single item at the local ItemSet. *Does not use* AllowItemChange(),
// ItemChange(), PostItemChange() and ItemSetChanged() calls.
void SetObjectItemNoBroadcast(const SfxPoolItem& rItem);
+ double GetCameraZRotation() const;
public:
diff --git a/svx/qa/unit/customshapes.cxx b/svx/qa/unit/customshapes.cxx
index 10abdad0f7e3..e42c7ad2fde9 100644
--- a/svx/qa/unit/customshapes.cxx
+++ b/svx/qa/unit/customshapes.cxx
@@ -520,7 +520,7 @@ CPPUNIT_TEST_FIXTURE(CustomshapesTest, testTdf126060_3D_Z_Rotation)
SdrObjCustomShape& rSdrObjCustomShape(
static_cast<SdrObjCustomShape&>(*GetSdrObjectFromXShape(xShape)));
- if (rSdrObjCustomShape.GetCameraRotation() != 90)
+ if (rSdrObjCustomShape.GetCameraZRotation() != 90)
sErrors += "Wrong text camera Z rotation";
basegfx::B2DHomMatrix aObjectTransform;
diff --git a/svx/source/sdr/contact/viewcontactofsdrobjcustomshape.cxx b/svx/source/sdr/contact/viewcontactofsdrobjcustomshape.cxx
index ccc70b0d3805..2b1a1913f003 100644
--- a/svx/source/sdr/contact/viewcontactofsdrobjcustomshape.cxx
+++ b/svx/source/sdr/contact/viewcontactofsdrobjcustomshape.cxx
@@ -159,18 +159,13 @@ namespace sdr::contact
// #i101684# get the text range unrotated and absolute to the object range
const basegfx::B2DRange aTextRange(getCorrectedTextBoundRect());
- // Get the text range before unrotated and independent from object range
- const tools::Rectangle aIndTextRect(Point(aTextRange.getMinX(), aTextRange.getMinY()), GetCustomShapeObj().GetTextSize());
- const basegfx::B2DRange aIndTextRange = vcl::unotools::b2DRectangleFromRectangle(aIndTextRect);
-
// Rotation before scaling
- if(!basegfx::fTools::equalZero(GetCustomShapeObj().GetExtraTextRotation(true)) ||
- !basegfx::fTools::equalZero(GetCustomShapeObj().GetCameraRotation()))
+ if(!basegfx::fTools::equalZero(GetCustomShapeObj().GetExtraTextRotation(true)))
{
basegfx::B2DVector aTranslation(0.5, 0.5);
aTextBoxMatrix.translate( -aTranslation.getX(), -aTranslation.getY() );
aTextBoxMatrix.rotate(basegfx::deg2rad(
- 360.0 - GetCustomShapeObj().GetExtraTextRotation(true) - GetCustomShapeObj().GetCameraRotation()));
+ 360.0 - GetCustomShapeObj().GetExtraTextRotation(true)));
aTextBoxMatrix.translate( aTranslation.getX(), aTranslation.getY() );
}
// give text object a size
@@ -178,7 +173,6 @@ namespace sdr::contact
// check if we have a rotation/shear at all to take care of
const double fExtraTextRotation(GetCustomShapeObj().GetExtraTextRotation());
- const double fTextCameraZRotation(GetCustomShapeObj().GetCameraRotation());
const GeoStat& rGeoStat(GetCustomShapeObj().GetGeoStat());
if(rGeoStat.nShearAngle || rGeoStat.nRotationAngle || !basegfx::fTools::equalZero(fExtraTextRotation))
@@ -191,13 +185,13 @@ namespace sdr::contact
aTextRange.getMinY() - aObjectRange.getMinimum().getY());
}
- if(!basegfx::fTools::equalZero(fExtraTextRotation) || !basegfx::fTools::equalZero(fTextCameraZRotation))
+ if(!basegfx::fTools::equalZero(fExtraTextRotation))
{
basegfx::B2DVector aTranslation(
( aTextRange.getWidth() / 2 ) + ( aTextRange.getMinX() - aObjectRange.getMinimum().getX() ),
( aTextRange.getHeight() / 2 ) + ( aTextRange.getMinY() - aObjectRange.getMinimum().getY() ) );
aTextBoxMatrix.translate( -aTranslation.getX(), -aTranslation.getY() );
- aTextBoxMatrix.rotate(basegfx::deg2rad(360.0 - fExtraTextRotation + fTextCameraZRotation));
+ aTextBoxMatrix.rotate(basegfx::deg2rad(360.0 - fExtraTextRotation));
aTextBoxMatrix.translate( aTranslation.getX(), aTranslation.getY() );
}
@@ -214,13 +208,6 @@ namespace sdr::contact
// give text it's target position
aTextBoxMatrix.translate(aObjectRange.getMinimum().getX(), aObjectRange.getMinimum().getY());
}
- // If text overflows from textbox we should use text info instead of textbox to relocation.
- else if((aTextRange.getWidth() < aIndTextRange.getWidth() ||
- aTextRange.getHeight() < aIndTextRange.getHeight()) &&
- !basegfx::fTools::equalZero(fTextCameraZRotation))
- {
- aTextBoxMatrix.translate(aIndTextRange.getCenterX(), aIndTextRange.getCenterY());
- }
else
{
aTextBoxMatrix.translate(aTextRange.getMinX(), aTextRange.getMinY());
diff --git a/svx/source/svdraw/svdoashp.cxx b/svx/source/svdraw/svdoashp.cxx
index fd708af04550..4a3910174f6f 100644
--- a/svx/source/svdraw/svdoashp.cxx
+++ b/svx/source/svdraw/svdoashp.cxx
@@ -511,22 +511,6 @@ double SdrObjCustomShape::GetExtraTextRotation( const bool bPreRotation ) const
return fExtraTextRotateAngle;
}
-double SdrObjCustomShape::GetCameraRotation() const
-{
- const css::uno::Any* pAny;
- double fTextCameraZRotateAngle = 0.0;
- const SdrCustomShapeGeometryItem& rGeometryItem = GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY );
-
- pAny = rGeometryItem.GetPropertyValueByName("TextCameraZRotateAngle");
-
- if ( pAny )
- *pAny >>= fTextCameraZRotateAngle;
-
- return fTextCameraZRotateAngle;
-}
-
-
-
bool SdrObjCustomShape::GetTextBounds( tools::Rectangle& rTextBound ) const
{
bool bRet = false;
diff --git a/svx/source/svdraw/svdotextdecomposition.cxx b/svx/source/svdraw/svdotextdecomposition.cxx
index 1650ffa71fab..aacc10bf4b7b 100644
--- a/svx/source/svdraw/svdotextdecomposition.cxx
+++ b/svx/source/svdraw/svdotextdecomposition.cxx
@@ -23,6 +23,7 @@
#include <svx/svdpage.hxx>
#include <svx/svdotext.hxx>
#include <svx/svdmodel.hxx>
+#include <svx/sdasitm.hxx>
#include <textchain.hxx>
#include <textchainflow.hxx>
#include <svx/sdtacitm.hxx>
@@ -43,6 +44,7 @@
#include <drawinglayer/animation/animationtiming.hxx>
#include <basegfx/color/bcolor.hxx>
#include <vcl/svapp.hxx>
+#include <vcl/canvastools.hxx>
#include <editeng/escapementitem.hxx>
#include <editeng/svxenum.hxx>
#include <editeng/flditem.hxx>
@@ -1109,6 +1111,23 @@ void SdrTextObj::impDecomposeBlockTextPrimitive(
const basegfx::B2DTuple aAdjOffset(fStartInX, fStartInY);
basegfx::B2DHomMatrix aNewTransformA(basegfx::utils::createTranslateB2DHomMatrix(aAdjOffset.getX(), aAdjOffset.getY()));
+ // Apply the camera rotation. It have to be applied after adjustment of
+ // the text (top, bottom, center, left, right).
+ if(GetCameraZRotation() != 0)
+ {
+ // First find the text rect.
+ basegfx::B2DRange aTextRectangle(/*x1=*/aTranslate.getX() + aAdjustTranslate.getX(),
+ /*y1=*/aTranslate.getY() + aAdjustTranslate.getY(),
+ /*x2=*/aTranslate.getX() + aOutlinerScale.getX() - aAdjustTranslate.getX(),
+ /*y2=*/aTranslate.getY() + aOutlinerScale.getY() - aAdjustTranslate.getY());
+
+ // Rotate the text from the center point.
+ basegfx::B2DVector aTranslateToCenter(aTextRectangle.getWidth() / 2, aTextRectangle.getHeight() / 2);
+ aNewTransformA.translate(-aTranslateToCenter.getX(), -aTranslateToCenter.getY());
+ aNewTransformA.rotate(basegfx::deg2rad(360.0 - GetCameraZRotation() ));
+ aNewTransformA.translate(aTranslateToCenter.getX(), aTranslateToCenter.getY());
+ }
+
// mirroring. We are now in aAnchorTextRange sizes. When mirroring in X and Y,
// move the null point which was top left to bottom right.
const bool bMirrorX(basegfx::fTools::less(aScale.getX(), 0.0));
@@ -1120,6 +1139,7 @@ void SdrTextObj::impDecomposeBlockTextPrimitive(
bMirrorX ? -1.0 : 1.0, bMirrorY ? -1.0 : 1.0,
fShearX, fRotate, aTranslate.getX(), aTranslate.getY()));
+
// create ClipRange (if needed)
basegfx::B2DRange aClipRange;
@@ -1658,4 +1678,19 @@ void SdrTextObj::impDecomposeBlockTextPrimitiveDirect(
rTarget.append(aConverter.getPrimitive2DSequence());
}
+double SdrTextObj::GetCameraZRotation() const
+{
+ const css::uno::Any* pAny;
+ double fTextCameraZRotateAngle = 0.0;
+ const SfxItemSet& rSet = GetObjectItemSet();
+ const SdrCustomShapeGeometryItem& rGeometryItem(rSet.Get(SDRATTR_CUSTOMSHAPE_GEOMETRY));
+
+ pAny = rGeometryItem.GetPropertyValueByName("TextCameraZRotateAngle");
+
+ if ( pAny )
+ *pAny >>= fTextCameraZRotateAngle;
+
+ return fTextCameraZRotateAngle;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 3503c03ece2fd912f4ba4767894eb97d8f9aae07
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Thu Oct 15 21:03:59 2020 +0200
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Oct 16 12:04:52 2020 +0200
pdfium: add an FPDFBitmap_Create() wrapper
Fixes a leak in PDFiumPage::getChecksum().
Change-Id: I57471a26702f1d3dd69e9e18a4067ce0e724e358
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104386
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
diff --git a/include/vcl/filter/PDFiumLibrary.hxx b/include/vcl/filter/PDFiumLibrary.hxx
index f6687cceacb1..ee8a453a8b15 100644
--- a/include/vcl/filter/PDFiumLibrary.hxx
+++ b/include/vcl/filter/PDFiumLibrary.hxx
@@ -38,6 +38,7 @@ constexpr char constDictionaryKeyPopup[] = "Popup";
constexpr char constDictionaryKeyModificationDate[] = "M";
constexpr char constDictionaryKeyInteriorColor[] = "IC";
+class PDFiumBitmap;
class PDFiumDocument;
class PDFiumPageObject;
@@ -56,6 +57,7 @@ public:
OUString getLastError() const { return maLastError; }
std::unique_ptr<PDFiumDocument> openDocument(const void* pData, int nSize);
+ std::unique_ptr<PDFiumBitmap> createBitmap(int nWidth, int nHeight, int nAlpha);
};
class VCL_DLLPUBLIC PDFiumBitmap final
diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx
index 5e113ff2aba8..605ea45f8c23 100644
--- a/vcl/source/filter/ipdf/pdfread.cxx
+++ b/vcl/source/filter/ipdf/pdfread.cxx
@@ -155,24 +155,24 @@ size_t RenderPDFBitmaps(const void* pBuffer, int nSize, std::vector<Bitmap>& rBi
auto pPdfium = vcl::pdf::PDFiumLibrary::get();
// Load the buffer using pdfium.
- FPDF_DOCUMENT pPdfDocument = FPDF_LoadMemDocument(pBuffer, nSize, /*password=*/nullptr);
+ std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = pPdfium->openDocument(pBuffer, nSize);
if (!pPdfDocument)
return 0;
- const int nPageCount = FPDF_GetPageCount(pPdfDocument);
+ const int nPageCount = pPdfDocument->getPageCount();
if (nPages <= 0)
nPages = nPageCount;
const size_t nLastPage = std::min<int>(nPageCount, nFirstPage + nPages) - 1;
for (size_t nPageIndex = nFirstPage; nPageIndex <= nLastPage; ++nPageIndex)
{
// Render next page.
- FPDF_PAGE pPdfPage = FPDF_LoadPage(pPdfDocument, nPageIndex);
+ std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage = pPdfDocument->openPage(nPageIndex);
if (!pPdfPage)
break;
// Calculate the bitmap size in points.
- size_t nPageWidthPoints = FPDF_GetPageWidth(pPdfPage);
- size_t nPageHeightPoints = FPDF_GetPageHeight(pPdfPage);
+ size_t nPageWidthPoints = pPdfPage->getWidth();
+ size_t nPageHeightPoints = pPdfPage->getHeight();
if (pSizeHint && pSizeHint->getX() && pSizeHint->getY())
{
// Have a size hint, prefer that over the logic size from the PDF.
@@ -183,21 +183,24 @@ size_t RenderPDFBitmaps(const void* pBuffer, int nSize, std::vector<Bitmap>& rBi
// Returned unit is points, convert that to pixel.
const size_t nPageWidth = pointToPixel(nPageWidthPoints, fResolutionDPI);
const size_t nPageHeight = pointToPixel(nPageHeightPoints, fResolutionDPI);
- FPDF_BITMAP pPdfBitmap = FPDFBitmap_Create(nPageWidth, nPageHeight, /*alpha=*/1);
+ std::unique_ptr<vcl::pdf::PDFiumBitmap> pPdfBitmap
+ = pPdfium->createBitmap(nPageWidth, nPageHeight, /*alpha=*/1);
if (!pPdfBitmap)
break;
- const FPDF_DWORD nColor = FPDFPage_HasTransparency(pPdfPage) ? 0x00000000 : 0xFFFFFFFF;
- FPDFBitmap_FillRect(pPdfBitmap, 0, 0, nPageWidth, nPageHeight, nColor);
- FPDF_RenderPageBitmap(pPdfBitmap, pPdfPage, /*start_x=*/0, /*start_y=*/0, nPageWidth,
- nPageHeight, /*rotate=*/0, /*flags=*/0);
+ const FPDF_DWORD nColor
+ = FPDFPage_HasTransparency(pPdfPage->getPointer()) ? 0x00000000 : 0xFFFFFFFF;
+ FPDFBitmap_FillRect(pPdfBitmap->getPointer(), 0, 0, nPageWidth, nPageHeight, nColor);
+ FPDF_RenderPageBitmap(pPdfBitmap->getPointer(), pPdfPage->getPointer(), /*start_x=*/0,
+ /*start_y=*/0, nPageWidth, nPageHeight, /*rotate=*/0, /*flags=*/0);
// Save the buffer as a bitmap.
Bitmap aBitmap(Size(nPageWidth, nPageHeight), 24);
{
BitmapScopedWriteAccess pWriteAccess(aBitmap);
- const auto pPdfBuffer = static_cast<ConstScanline>(FPDFBitmap_GetBuffer(pPdfBitmap));
- const int nStride = FPDFBitmap_GetStride(pPdfBitmap);
+ const auto pPdfBuffer
+ = static_cast<ConstScanline>(FPDFBitmap_GetBuffer(pPdfBitmap->getPointer()));
+ const int nStride = FPDFBitmap_GetStride(pPdfBitmap->getPointer());
for (size_t nRow = 0; nRow < nPageHeight; ++nRow)
{
ConstScanline pPdfLine = pPdfBuffer + (nStride * nRow);
@@ -207,12 +210,8 @@ size_t RenderPDFBitmaps(const void* pBuffer, int nSize, std::vector<Bitmap>& rBi
}
rBitmaps.emplace_back(std::move(aBitmap));
- FPDFBitmap_Destroy(pPdfBitmap);
- FPDF_ClosePage(pPdfPage);
}
- FPDF_CloseDocument(pPdfDocument);
-
return rBitmaps.size();
#else
(void)pBuffer;
diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx
index 64fdd6a7e0d4..32c33580d1df 100644
--- a/vcl/source/pdf/PDFiumLibrary.cxx
+++ b/vcl/source/pdf/PDFiumLibrary.cxx
@@ -139,6 +139,21 @@ std::unique_ptr<PDFiumDocument> PDFium::openDocument(const void* pData, int nSiz
return pPDFiumDocument;
}
+std::unique_ptr<PDFiumBitmap> PDFium::createBitmap(int nWidth, int nHeight, int nAlpha)
+{
+ std::unique_ptr<PDFiumBitmap> pPDFiumBitmap;
+ FPDF_BITMAP pPdfBitmap = FPDFBitmap_Create(nWidth, nHeight, nAlpha);
+ if (!pPdfBitmap)
+ {
+ maLastError = "Failed to create bitmap";
+ }
+ else
+ {
+ pPDFiumBitmap = std::make_unique<PDFiumBitmap>(pPdfBitmap);
+ }
+ return pPDFiumBitmap;
+}
+
PDFiumDocument::PDFiumDocument(FPDF_DOCUMENT pPdfDocument)
: mpPdfDocument(pPdfDocument)
{
@@ -377,7 +392,8 @@ BitmapChecksum PDFiumPage::getChecksum()
{
size_t nPageWidth = getWidth();
size_t nPageHeight = getHeight();
- FPDF_BITMAP pPdfBitmap = FPDFBitmap_Create(nPageWidth, nPageHeight, /*alpha=*/1);
+ auto pPdfBitmap
+ = std::make_unique<PDFiumBitmap>(FPDFBitmap_Create(nPageWidth, nPageHeight, /*alpha=*/1));
if (!pPdfBitmap)
{
return 0;
@@ -385,13 +401,15 @@ BitmapChecksum PDFiumPage::getChecksum()
// Intentionally not using FPDF_ANNOT here, annotations/commenting is OK to not affect the
// checksum, signature verification wants this.
- FPDF_RenderPageBitmap(pPdfBitmap, mpPage, /*start_x=*/0, /*start_y=*/0, nPageWidth, nPageHeight,
+ FPDF_RenderPageBitmap(pPdfBitmap->getPointer(), mpPage, /*start_x=*/0, /*start_y=*/0,
+ nPageWidth, nPageHeight,
/*rotate=*/0, /*flags=*/0);
Bitmap aBitmap(Size(nPageWidth, nPageHeight), 24);
{
BitmapScopedWriteAccess pWriteAccess(aBitmap);
- const auto pPdfBuffer = static_cast<ConstScanline>(FPDFBitmap_GetBuffer(pPdfBitmap));
- const int nStride = FPDFBitmap_GetStride(pPdfBitmap);
+ const auto pPdfBuffer
+ = static_cast<ConstScanline>(FPDFBitmap_GetBuffer(pPdfBitmap->getPointer()));
+ const int nStride = FPDFBitmap_GetStride(pPdfBitmap->getPointer());
for (size_t nRow = 0; nRow < nPageHeight; ++nRow)
{
ConstScanline pPdfLine = pPdfBuffer + (nStride * nRow);
More information about the Libreoffice-commits
mailing list