From d9637f12e1e915ff98237b783005f81d9e47fd30 Mon Sep 17 00:00:00 2001 From: "Elena.Subbotina" Date: Mon, 11 Dec 2023 13:23:33 +0300 Subject: [PATCH 1/6] fix build --- DesktopEditor/raster/PICT/PICFile.cpp | 108 +++-- DesktopEditor/raster/PICT/PICFile.h | 31 ++ DesktopEditor/raster/PICT/pic.cpp | 191 +++++---- DesktopEditor/raster/PICT/pic.h | 556 ++++++++++++-------------- 4 files changed, 465 insertions(+), 421 deletions(-) diff --git a/DesktopEditor/raster/PICT/PICFile.cpp b/DesktopEditor/raster/PICT/PICFile.cpp index 83cfe3b78c..8b9c4d8878 100644 --- a/DesktopEditor/raster/PICT/PICFile.cpp +++ b/DesktopEditor/raster/PICT/PICFile.cpp @@ -1,3 +1,34 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2023 + * + * This program is a free software product. You can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License (AGPL) + * version 3 as published by the Free Software Foundation. In accordance with + * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect + * that Ascensio System SIA expressly excludes the warranty of non-infringement + * of any third-party rights. + * + * This program is distributed WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For + * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html + * + * You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish + * street, Riga, Latvia, EU, LV-1050. + * + * The interactive user interfaces in modified source and object code versions + * of the Program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU AGPL version 3. + * + * Pursuant to Section 7(b) of the License you must retain the original Product + * logo when distributing the program. Pursuant to Section 7(e) we decline to + * grant you any rights under trademark law for use of our trademarks. + * + * All the Product's GUI elements, including illustrations and icon sets, as + * well as technical writing content are licensed under the terms of the + * Creative Commons Attribution-ShareAlike 4.0 International. See the License + * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + * + */ #include "PICFile.h" #include "pic.h" @@ -5,7 +36,8 @@ namespace PICT { -bool ImageToFrame(ImagePICT* pImage, CBgraFrame* pFrame, bool isRGBA) { +bool ImageToFrame(ImagePICT* pImage, CBgraFrame* pFrame, bool isRGBA) +{ int nWidth = pImage->m_nWidth; int nHeight = pImage->m_nHeight; int BufferSize = 4 * nWidth * nHeight; @@ -30,10 +62,10 @@ bool ImageToFrame(ImagePICT* pImage, CBgraFrame* pFrame, bool isRGBA) { unsigned int indG = 1; unsigned int indB = isRGBA ? 0 : 2; - for (int i = 0; i < pImage->m_nHeight; i++) + for (size_t i = 0; i < pImage->m_nHeight; i++) { unsigned char* q = pImage->ppixels + pImage->number_channels * (i * pImage->m_nWidth); - for (int j = 0; j < pImage->m_nWidth; j++) + for (size_t j = 0; j < pImage->m_nWidth; j++) { pBufferPtr[indR] = *(q + 2); pBufferPtr[indG] = *(q + 1); @@ -49,58 +81,56 @@ bool ImageToFrame(ImagePICT* pImage, CBgraFrame* pFrame, bool isRGBA) { //////////////////////////////////////////////////////////////////////////////////////// -bool CPictFile::Open(CBgraFrame *pFrame, const std::wstring &strFileName, bool isRGBA) { - ImagePICT* pImage = new ImagePICT; - - AquireImage(pImage); - +bool CPictFile::Open(CBgraFrame *pFrame, const std::wstring &strFileName, bool isRGBA) +{ NSFile::CFileBinary oFile; if (!oFile.OpenFile(strFileName)) return false; - if (DecodePICT(oFile.GetFileNative(), pImage)) - { - bool status = ImageToFrame(pImage, pFrame, isRGBA); - DestroyImage(pImage); - oFile.CloseFile(); - - return status; - } - else - { - DestroyImage(pImage); - oFile.CloseFile(); - - return false; - } -} - -bool CPictFile::Open(CBgraFrame *pFrame, BYTE *pBuffer, int nSize, bool isRGBA) { ImagePICT* pImage = new ImagePICT; - AquireImage(pImage); + bool status = false; + if (DecodePICT(oFile.GetFileNative(), pImage)) + { + status = ImageToFrame(pImage, pFrame, isRGBA); + } + + DestroyImage(pImage); + oFile.CloseFile(); + + return status; +} + +bool CPictFile::Open(CBgraFrame *pFrame, BYTE *pBuffer, int nSize, bool isRGBA) +{ NSFile::CFileBinary oFile; - if (!oFile.CreateTempFile()) + std::wstring sTmpFile = NSFile::CFileBinary::CreateTempFileWithUniqueName(NSFile::CFileBinary::GetTempPath(), L"pct"); + + if (sTmpFile.empty()) return false; + if (!oFile.CreateFile(sTmpFile)) + return false; + + ImagePICT* pImage = new ImagePICT; + AquireImage(pImage); + oFile.WriteFile(pBuffer, nSize); oFile.SetPosition(0); + bool status = false; if (DecodePICT(oFile.GetFileNative(), pImage)) { - bool status = ImageToFrame(pImage, pFrame, isRGBA); - DestroyImage(pImage); - oFile.CloseFile(); - - return status; + status = ImageToFrame(pImage, pFrame, isRGBA); } - else - { - DestroyImage(pImage); - oFile.CloseFile(); - return false; - } + DestroyImage(pImage); + oFile.CloseFile(); + + if (NSFile::CFileBinary::Exists(sTmpFile)) + NSFile::CFileBinary::Remove(sTmpFile); + + return status; } } diff --git a/DesktopEditor/raster/PICT/PICFile.h b/DesktopEditor/raster/PICT/PICFile.h index 4de4c31ea0..40daae02f2 100644 --- a/DesktopEditor/raster/PICT/PICFile.h +++ b/DesktopEditor/raster/PICT/PICFile.h @@ -1,3 +1,34 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2023 + * + * This program is a free software product. You can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License (AGPL) + * version 3 as published by the Free Software Foundation. In accordance with + * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect + * that Ascensio System SIA expressly excludes the warranty of non-infringement + * of any third-party rights. + * + * This program is distributed WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For + * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html + * + * You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish + * street, Riga, Latvia, EU, LV-1050. + * + * The interactive user interfaces in modified source and object code versions + * of the Program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU AGPL version 3. + * + * Pursuant to Section 7(b) of the License you must retain the original Product + * logo when distributing the program. Pursuant to Section 7(e) we decline to + * grant you any rights under trademark law for use of our trademarks. + * + * All the Product's GUI elements, including illustrations and icon sets, as + * well as technical writing content are licensed under the terms of the + * Creative Commons Attribution-ShareAlike 4.0 International. See the License + * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + * + */ #ifndef PICFILE_H #define PICFILE_H diff --git a/DesktopEditor/raster/PICT/pic.cpp b/DesktopEditor/raster/PICT/pic.cpp index 795b45a680..749b829cf1 100644 --- a/DesktopEditor/raster/PICT/pic.cpp +++ b/DesktopEditor/raster/PICT/pic.cpp @@ -1,3 +1,34 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2023 + * + * This program is a free software product. You can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License (AGPL) + * version 3 as published by the Free Software Foundation. In accordance with + * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect + * that Ascensio System SIA expressly excludes the warranty of non-infringement + * of any third-party rights. + * + * This program is distributed WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For + * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html + * + * You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish + * street, Riga, Latvia, EU, LV-1050. + * + * The interactive user interfaces in modified source and object code versions + * of the Program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU AGPL version 3. + * + * Pursuant to Section 7(b) of the License you must retain the original Product + * logo when distributing the program. Pursuant to Section 7(e) we decline to + * grant you any rights under trademark law for use of our trademarks. + * + * All the Product's GUI elements, including illustrations and icon sets, as + * well as technical writing content are licensed under the terms of the + * Creative Commons Attribution-ShareAlike 4.0 International. See the License + * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + * + */ #include "pic.h" static const PICTCode @@ -17,8 +48,8 @@ static const PICTCode /* 0x0b */ { "OvSize", 4, "oval size (point)" }, /* 0x0c */ { "Origin", 4, "dh, dv (word)" }, /* 0x0d */ { "TxSize", 2, "text size (word)" }, - /* 0x0e */ { "FgColor", 4, "foreground color (ssize_tword)" }, - /* 0x0f */ { "BkColor", 4, "background color (ssize_tword)" }, + /* 0x0e */ { "FgColor", 4, "foreground color (long longword)" }, + /* 0x0f */ { "BkColor", 4, "background color (long longword)" }, /* 0x10 */ { "TxRatio", 8, "numerator (point), denominator (point)" }, /* 0x11 */ { "Version", 1, "version (byte)" }, /* 0x12 */ { "BkPixPat", 0, "color background pattern" }, @@ -422,7 +453,7 @@ PixelChannelMap *AcquirePixelChannelMap() PixelChannelMap *channel_map; - ssize_t + long long i; channel_map=(PixelChannelMap *) malloc(65*sizeof(*channel_map)); @@ -472,20 +503,20 @@ unsigned char GetPixelWriteMask(const ImagePICT *image,const unsigned char *pixe return(pixel[image->channel_map[WriteMaskPixelChannel].offset]); } -int IsValidOffset(const ssize_t x, const size_t a) +int IsValidOffset(const long long x, const size_t a) { if (a == 0) return 0; - if ((x >= (LLONG_MAX / 64 / (ssize_t) a)) || - (x <= ((-LLONG_MAX - 1) / 64 / (ssize_t) a))) + if ((x >= (LLONG_MAX / 64 / (long long) a)) || + (x <= ((-LLONG_MAX - 1) / 64 / (long long) a))) return 0; return 1; } -int ReadPixels(ImagePICT* image, const ssize_t x, const ssize_t y, const size_t width, const size_t height, unsigned char* pixels) +int ReadPixels(ImagePICT* image, const long long x, const long long y, const size_t width, const size_t height, unsigned char* pixels) { - ssize_t + long long offset, i; @@ -501,9 +532,9 @@ int ReadPixels(ImagePICT* image, const ssize_t x, const ssize_t y, const size_t if (IsValidOffset(y, image->m_nWidth) == 0) return 0; - offset = y * (ssize_t) image->m_nWidth; + offset = y * (long long) image->m_nWidth; - if ((offset/ (ssize_t) image->m_nWidth) != y) + if ((offset/ (long long) image->m_nWidth) != y) { strcpy(image->error, "UncorrectOffset"); @@ -544,7 +575,7 @@ int ReadPixels(ImagePICT* image, const ssize_t x, const ssize_t y, const size_t rows=1UL; } p = image->ppixels + image->number_channels * offset; - for (i=0; i < (ssize_t) rows; i++) + for (i=0; i < (long long) rows; i++) { (void) memcpy(q,p,(size_t) length); p += image->number_channels * image->m_nWidth; @@ -561,7 +592,7 @@ int ReadPixels(ImagePICT* image, const ssize_t x, const ssize_t y, const size_t return 1; } -unsigned char* GetPixels(ImagePICT* image, const ssize_t x, const ssize_t y, const size_t width, const size_t height) +unsigned char* GetPixels(ImagePICT* image, const long long x, const long long y, const size_t width, const size_t height) { unsigned char *pixels; @@ -613,7 +644,7 @@ void SetPixelChannel(const ImagePICT *image,const PixelChannel channel,const uns pixel[image->channel_map[channel].offset]=Quantum; } -PixelChannel GetPixelChannelChannel(const ImagePICT *image,const ssize_t offset) +PixelChannel GetPixelChannelChannel(const ImagePICT *image,const long long offset) { if ((offset < 0) || (offset >= 64)) return(UndefinedPixelChannel); @@ -719,7 +750,7 @@ int SetImageAlpha(ImagePICT* image, const unsigned char Alpha) int AquireImageColormap(ImagePICT* image, const size_t colors) { - ssize_t + long long i; if (image == (ImagePICT*) NULL) @@ -864,17 +895,17 @@ int SetImageColorspace(ImagePICT *image, const ColorspaceType colorspace) // return(status); //} -ssize_t CastDoubleToLong(const double x) +long long CastDoubleToLong(const double x) { if (floor(x) > ((double) LLONG_MAX-1)) { - return((ssize_t) LLONG_MAX); + return((long long) LLONG_MAX); } if (ceil(x) < ((double) LLONG_MIN+1)) { - return((ssize_t) LLONG_MIN); + return((long long) LLONG_MIN); } - return((ssize_t) x); + return((long long) x); } int Clamp(double x, double min, double max) { @@ -890,7 +921,7 @@ int Clamp(double x, double min, double max) { static inline int CopyPixel(const ImagePICT *image, const unsigned char *source,unsigned char *destination) { - ssize_t + long long i; if (source == (const unsigned char *) NULL) @@ -910,7 +941,7 @@ static inline int CopyPixel(const ImagePICT *image, return 1; } -int GetOneVirtualPixel(ImagePICT *image,const ssize_t x,const ssize_t y,unsigned char *pixel) +int GetOneVirtualPixel(ImagePICT *image,const long long x,const long long y,unsigned char *pixel) { const unsigned char *p; @@ -969,7 +1000,7 @@ void AquireImage(ImagePICT* image) size_t GetSize(FILE* file) { - ssize_t + long long file_discription; struct stat @@ -996,7 +1027,7 @@ int ReadByte(FILE* file) return getc(file); } -const void *ReadBlobStream(FILE* file, const size_t length, void *data, ssize_t* count) +const void *ReadBlobStream(FILE* file, const size_t length, void *data, long long* count) { *count = Read(file, length, (unsigned char*) data); return data; @@ -1013,7 +1044,7 @@ unsigned short ReadShortValue(FILE* file) const unsigned char *p; - ssize_t + long long count; *buffer='\0'; @@ -1304,7 +1335,7 @@ int IterateOverSplayTree(SplayTreeInfo *splay_tree, NodeInfo **nodes; - ssize_t + long long i; NodeInfo @@ -1643,7 +1674,7 @@ void WriteTo8BimProfile(ImagePICT *image,const char *name, const StringInfo *pro StringInfo *profile_8bim; - ssize_t + long long count; unsigned char @@ -1685,10 +1716,10 @@ void WriteTo8BimProfile(ImagePICT *image,const char *name, const StringInfo *pro if (p > (datum+length-4)) break; p=ReadResourceLong(p,&value); - count=(ssize_t) value; + count=(long long) value; if ((count & 0x01) != 0) count++; - if ((count < 0) || (p > (datum+length-count)) || (count > (ssize_t) length)) + if ((count < 0) || (p > (datum+length-count)) || (count > (long long) length)) break; if (id != profile_id) p+=count; @@ -1698,7 +1729,7 @@ void WriteTo8BimProfile(ImagePICT *image,const char *name, const StringInfo *pro extent, offset; - ssize_t + long long extract_extent; StringInfo @@ -1715,7 +1746,7 @@ void WriteTo8BimProfile(ImagePICT *image,const char *name, const StringInfo *pro else { offset=(size_t) (p-datum); - extract_extent=(ssize_t) profile->length; + extract_extent=(long long) profile->length; if ((extract_extent & 0x01) != 0) extract_extent++; extract_profile=AcquireStringInfo(offset+(size_t) extract_extent+ @@ -1873,7 +1904,7 @@ static inline unsigned char GetPixelReadMask(const ImagePICT *image, return(pixel[image->channel_map[ReadMaskPixelChannel].offset]); } -int CompositeImage(ImagePICT *image, const ImagePICT *composite, const int clip_to_self,const ssize_t x_offset,const ssize_t y_offset) +int CompositeImage(ImagePICT *image, const ImagePICT *composite, const int clip_to_self,const long long x_offset,const long long y_offset) { #define CompositeImageTag "Composite/Image" @@ -1892,7 +1923,7 @@ int CompositeImage(ImagePICT *image, const ImagePICT *composite, const int clip_ compose_sync, status; - ssize_t + long long progress; double @@ -1904,7 +1935,7 @@ int CompositeImage(ImagePICT *image, const ImagePICT *composite, const int clip_ source_dissolve, threshold; - ssize_t + long long y; image->storage_class = DirectClass; @@ -1932,14 +1963,14 @@ int CompositeImage(ImagePICT *image, const ImagePICT *composite, const int clip_ source_dissolve=1.0; threshold=0.05f; - if (!((x_offset < 0) || (y_offset < 0)) && !((x_offset+(ssize_t) source_image->m_nWidth) > (ssize_t) image->m_nWidth) && !((y_offset+(ssize_t) source_image->m_nHeight) > (ssize_t) image->m_nHeight)) + if (!((x_offset < 0) || (y_offset < 0)) && !((x_offset+(long long) source_image->m_nWidth) > (long long) image->m_nWidth) && !((y_offset+(long long) source_image->m_nHeight) > (long long) image->m_nHeight)) { if ((source_image->alpha_trait == UndefinedPixelTrait) && (image->alpha_trait != UndefinedPixelTrait)) (void) SetImageAlpha(source_image, (const unsigned char) 255); status = 1; - for (y=0; y < (ssize_t) source_image->m_nHeight; y++) + for (y=0; y < (long long) source_image->m_nHeight; y++) { const unsigned char *p; @@ -1947,7 +1978,7 @@ int CompositeImage(ImagePICT *image, const ImagePICT *composite, const int clip_ unsigned char *q; - ssize_t + long long x; if (status == 0) @@ -1959,9 +1990,9 @@ int CompositeImage(ImagePICT *image, const ImagePICT *composite, const int clip_ status=0; continue; } - for (x=0; x < (ssize_t) source_image->m_nWidth; x++) + for (x=0; x < (long long) source_image->m_nWidth; x++) { - ssize_t + long long i; if (GetPixelReadMask(source_image, p) <= (255/2)) { @@ -1995,7 +2026,7 @@ int CompositeImage(ImagePICT *image, const ImagePICT *composite, const int clip_ status=1; progress=0; midpoint=128.0; - for (y=0; y < (ssize_t) image->m_nHeight; y++) + for (y=0; y < (long long) image->m_nHeight; y++) { const unsigned char *pixels; @@ -2010,7 +2041,7 @@ int CompositeImage(ImagePICT *image, const ImagePICT *composite, const int clip_ unsigned char *q; - ssize_t + long long x; if (status == 0) @@ -2048,7 +2079,7 @@ int CompositeImage(ImagePICT *image, const ImagePICT *composite, const int clip_ } GetPixelInfo(image,&canvas_pixel); GetPixelInfo(source_image,&source_pixel); - for (x=0; x < (ssize_t) image->m_nHeight; x++) + for (x=0; x < (long long) image->m_nHeight; x++) { double gamma = 0.0; @@ -2067,7 +2098,7 @@ int CompositeImage(ImagePICT *image, const ImagePICT *composite, const int clip_ size_t channels; - ssize_t + long long i; if (clip_to_self != 0) @@ -2240,11 +2271,11 @@ int DecodeHeader(FILE* hFile, ImagePICT* image) if (c == 0x11) { - ssize_t version = ReadByte(hFile); + long long version = ReadByte(hFile); if (version == 2) { - ssize_t version2 = ReadByte(hFile); + long long version2 = ReadByte(hFile); if (version2 != 0xff) return 0; image->m_pctVersion = 2; @@ -2293,11 +2324,11 @@ int DecodeHeader(FILE* hFile, ImagePICT* image) } } - ssize_t version = ReadByte(hFile); + long long version = ReadByte(hFile); if (version == 2) { - ssize_t version2 = ReadByte(hFile); + long long version2 = ReadByte(hFile); if (version2 != 0xff) return 0; image->m_pctVersion = 2; @@ -2332,7 +2363,7 @@ static const unsigned char *UnpackScanline( const unsigned char *p; - ssize_t + long long i; unsigned char @@ -2348,7 +2379,7 @@ static const unsigned char *UnpackScanline( return(pixels); case 4: { - for (i=0; i < (ssize_t) *bytes_per_line; i++) + for (i=0; i < (long long) *bytes_per_line; i++) { *q++=(*p >> 4) & 0xff; *q++=(*p & 15); @@ -2359,7 +2390,7 @@ static const unsigned char *UnpackScanline( } case 2: { - for (i=0; i < (ssize_t) *bytes_per_line; i++) + for (i=0; i < (long long) *bytes_per_line; i++) { *q++=(*p >> 6) & 0x03; *q++=(*p >> 4) & 0x03; @@ -2372,7 +2403,7 @@ static const unsigned char *UnpackScanline( } case 1: { - for (i=0; i < (ssize_t) *bytes_per_line; i++) + for (i=0; i < (long long) *bytes_per_line; i++) { *q++=(*p >> 7) & 0x01; *q++=(*p >> 6) & 0x01; @@ -2405,7 +2436,7 @@ static unsigned char *DecodeImage(FILE *blob,ImagePICT *image, const unsigned char *p; - ssize_t + long long i; unsigned char @@ -2418,7 +2449,7 @@ static unsigned char *DecodeImage(FILE *blob,ImagePICT *image, scanline_length, width; - ssize_t + long long count, j, y; @@ -2472,12 +2503,12 @@ static unsigned char *DecodeImage(FILE *blob,ImagePICT *image, /* Pixels are already uncompressed. */ - for (y=0; y < (ssize_t) image->m_nHeight; y++) + for (y=0; y < (long long) image->m_nHeight; y++) { - q=pixels+y*(ssize_t) width*image->number_channels; + q=pixels+y*(long long) width*image->number_channels; number_pixels=bytes_per_line; count=Read(blob,(size_t) number_pixels,scanline); - if (count != (ssize_t) number_pixels) + if (count != (long long) number_pixels) { status=0; break; @@ -2498,9 +2529,9 @@ static unsigned char *DecodeImage(FILE *blob,ImagePICT *image, /* Uncompress RLE pixels into uncompressed pixel buffer. */ - for (y=0; y < (ssize_t) image->m_nHeight; y++) + for (y=0; y < (long long) image->m_nHeight; y++) { - q=pixels+y*(ssize_t) width; + q=pixels+y*(long long) width; if (bytes_per_line > 200) scanline_length=ReadShortValue(blob); else @@ -2511,22 +2542,22 @@ static unsigned char *DecodeImage(FILE *blob,ImagePICT *image, break; } count=Read(blob,scanline_length,scanline); - if (count != (ssize_t) scanline_length) + if (count != (long long) scanline_length) { status=0; break; } - for (j=0; j < (ssize_t) scanline_length; ) + for (j=0; j < (long long) scanline_length; ) if ((scanline[j] & 0x80) == 0) { length=(size_t) ((scanline[j] & 0xff)+1); number_pixels=length*bytes_per_pixel; p=UnpackScanline(scanline+j+1,bits_per_pixel,unpack_buffer, &number_pixels); - if ((size_t) (q-pixels+(ssize_t) number_pixels) <= *extent) + if ((size_t) (q-pixels+(long long) number_pixels) <= *extent) (void) memcpy(q,p,(size_t) number_pixels); q+=number_pixels; - j+=(ssize_t) (length*bytes_per_pixel+1); + j+=(long long) (length*bytes_per_pixel+1); } else { @@ -2534,13 +2565,13 @@ static unsigned char *DecodeImage(FILE *blob,ImagePICT *image, number_pixels=bytes_per_pixel; p=UnpackScanline(scanline+j+1,bits_per_pixel,unpack_buffer, &number_pixels); - for (i=0; i < (ssize_t) length; i++) + for (i=0; i < (long long) length; i++) { - if ((size_t) (q-pixels+(ssize_t) number_pixels) <= *extent) + if ((size_t) (q-pixels+(long long) number_pixels) <= *extent) (void) memcpy(q,p,(size_t) number_pixels); q+=number_pixels; } - j+=(ssize_t) bytes_per_pixel+1; + j+=(long long) bytes_per_pixel+1; } } free(scanline); @@ -2551,7 +2582,7 @@ static unsigned char *DecodeImage(FILE *blob,ImagePICT *image, int DecodePICT(FILE* hFile, ImagePICT* image) { - ssize_t + long long flags, i, j, @@ -2754,7 +2785,7 @@ int DecodePICT(FILE* hFile, ImagePICT* image) image->resolutionY = 1.0 * pixmap.vertical_resolution; (void) ReadLongValue(hFile); - flags=(ssize_t) ReadShortValue(hFile); + flags=(long long) ReadShortValue(hFile); length=ReadShortValue(hFile); if (length > GetSize(hFile)) @@ -2864,7 +2895,7 @@ int DecodePICT(FILE* hFile, ImagePICT* image) size_t k; - ssize_t + long long bytes_per_line; unsigned char @@ -2875,7 +2906,7 @@ int DecodePICT(FILE* hFile, ImagePICT* image) */ bytes_per_line = 0; if ((code != 0x9a) && (code != 0x9b)) - bytes_per_line= (ssize_t) ReadShortValue(hFile); + bytes_per_line= (long long) ReadShortValue(hFile); else { (void) ReadShortValue(hFile); @@ -2943,7 +2974,7 @@ int DecodePICT(FILE* hFile, ImagePICT* image) if ((bytes_per_line & 0x8000) != 0) { (void) ReadLongValue(hFile); - flags = (ssize_t) ReadShortValue(hFile); + flags = (long long) ReadShortValue(hFile); tile_image->colors = 1UL * ReadShortValue(hFile) + 1; } status = AquireImageColormap(tile_image, tile_image->colors); @@ -2970,7 +3001,7 @@ int DecodePICT(FILE* hFile, ImagePICT* image) } else { - for (i=0; i < (ssize_t) tile_image->colors; i++) + for (i=0; i < (long long) tile_image->colors; i++) { tile_image->colormap[i].red=((double) 255 - tile_image->colormap[i].red); tile_image->colormap[i].green=((double) 255 - tile_image->colormap[i].green); @@ -3055,7 +3086,7 @@ int DecodePICT(FILE* hFile, ImagePICT* image) Convert PICT tile image to pixel packets. */ p = pixels; - for (y=0; y < (ssize_t) tile_image->m_nHeight; y++) + for (y=0; y < (long long) tile_image->m_nHeight; y++) { if (p > (pixels+extent+image->m_nWidth)) { @@ -3075,21 +3106,21 @@ int DecodePICT(FILE* hFile, ImagePICT* image) { if (tile_image->storage_class == PseudoClass) { - if ((index > 0) && (index <= (ssize_t) image->colors)) + if ((index > 0) && (index <= (long long) image->colors)) index=(unsigned char) *p; SetPixelIndex(tile_image,index,q); SetPixelRed(tile_image, - tile_image->colormap[(ssize_t) index].red,q); + tile_image->colormap[(long long) index].red,q); SetPixelGreen(tile_image, - tile_image->colormap[(ssize_t) index].green,q); + tile_image->colormap[(long long) index].green,q); SetPixelBlue(tile_image, - tile_image->colormap[(ssize_t) index].blue,q); + tile_image->colormap[(long long) index].blue,q); } else { if (pixmap.bits_per_pixel == 16) { - i=(ssize_t) (*p++); + i=(long long) (*p++); k=(size_t) (*p); SetPixelRed(tile_image,(unsigned char) ((i & 0x7c) << 1),q); SetPixelGreen(tile_image,(unsigned char) ((size_t) ((i & 0x03) << 6) |((k & 0xe0) >> 2)),q); @@ -3138,7 +3169,7 @@ int DecodePICT(FILE* hFile, ImagePICT* image) if ((tile_image->storage_class == DirectClass) && (pixmap.bits_per_pixel != 16)) { - p+=(pixmap.component_count-1)*(ssize_t) tile_image->m_nWidth; + p+=(pixmap.component_count-1)*(long long) tile_image->m_nWidth; if (p < pixels) break; } @@ -3148,7 +3179,7 @@ int DecodePICT(FILE* hFile, ImagePICT* image) if ((jpeg == 0) && (feof(hFile) == 0)) if ((code == 0x9a) || (code == 0x9b) || ((bytes_per_line & 0x8000) != 0)) - (void) CompositeImage(image,tile_image,1,(ssize_t) destination.left,(ssize_t)destination.top); + (void) CompositeImage(image,tile_image,1,(long long) destination.left,(long long)destination.top); tile_image=DestroyImage(tile_image); break; } @@ -3246,7 +3277,7 @@ int DecodePICT(FILE* hFile, ImagePICT* image) if (codes[code].length == -1) (void) ReadShortValue(hFile); else - for (i=0; i < (ssize_t) codes[code].length; i++) + for (i=0; i < (long long) codes[code].length; i++) if (ReadByte(hFile) == EOF) break; } @@ -3282,7 +3313,7 @@ int DecodePICT(FILE* hFile, ImagePICT* image) return 0; } - for (i=0; i < (ssize_t) length; i++) + for (i=0; i < (long long) length; i++) if (ReadByte(hFile) == EOF) break; continue; @@ -3302,7 +3333,7 @@ int DecodePICT(FILE* hFile, ImagePICT* image) return 0; } - for (i=0; i < (ssize_t) length; i++) + for (i=0; i < (long long) length; i++) if (ReadByte(hFile) == EOF) break; continue; diff --git a/DesktopEditor/raster/PICT/pic.h b/DesktopEditor/raster/PICT/pic.h index 5b8b894e05..2e938a2dd1 100644 --- a/DesktopEditor/raster/PICT/pic.h +++ b/DesktopEditor/raster/PICT/pic.h @@ -1,3 +1,35 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2023 + * + * This program is a free software product. You can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License (AGPL) + * version 3 as published by the Free Software Foundation. In accordance with + * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect + * that Ascensio System SIA expressly excludes the warranty of non-infringement + * of any third-party rights. + * + * This program is distributed WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For + * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html + * + * You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish + * street, Riga, Latvia, EU, LV-1050. + * + * The interactive user interfaces in modified source and object code versions + * of the Program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU AGPL version 3. + * + * Pursuant to Section 7(b) of the License you must retain the original Product + * logo when distributing the program. Pursuant to Section 7(e) we decline to + * grant you any rights under trademark law for use of our trademarks. + * + * All the Product's GUI elements, including illustrations and icon sets, as + * well as technical writing content are licensed under the terms of the + * Creative Commons Attribution-ShareAlike 4.0 International. See the License + * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + * + */ + #ifndef PIC_H #define PIC_H @@ -15,427 +47,347 @@ #include #include -typedef long long ssize_t ; - typedef enum { - UndefinedType, - BilevelType, - GrayscaleType, - GrayscaleAlphaType, - PaletteType, - PaletteAlphaType, - TrueColorType, - TrueColorAlphaType, - ColorSeparationType, - ColorSeparationAlphaType, - OptimizeType, - PaletteBilevelAlphaType + UndefinedType, + BilevelType, + GrayscaleType, + GrayscaleAlphaType, + PaletteType, + PaletteAlphaType, + TrueColorType, + TrueColorAlphaType, + ColorSeparationType, + ColorSeparationAlphaType, + OptimizeType, + PaletteBilevelAlphaType } ImageType; typedef struct { - char - *path; + char* path; + unsigned char* datum; - unsigned char - *datum; + size_t length; + size_t signature; - size_t - length, - signature; - - char - *name; + char* name; } StringInfo; typedef struct _NodeInfo { - void - *key; + void* key; + void* value; - void - *value; - - struct _NodeInfo - *left, - *right; + struct _NodeInfo* left; + struct _NodeInfo* right; } NodeInfo; typedef struct { - NodeInfo - *root; + NodeInfo* root; - int - (*compare)(const void *,const void *); + int (*compare)(const void*, const void*); - int - balance; + int balance; - void - *key, - *next; + void* key; + void* next; - size_t - nodes; + size_t nodes; - size_t - signature; + size_t signature; } SplayTreeInfo; typedef struct _PrimaryInfo { - double - x, - y, - z; + double x; + double y; + double z; } PrimaryInfo; typedef struct _ChromaticityInfo { - PrimaryInfo - red_primary, - green_primary, - blue_primary, - white_point; + PrimaryInfo red_primary; + PrimaryInfo green_primary; + PrimaryInfo blue_primary; + PrimaryInfo white_point; } ChromaticityInfo; typedef struct _PICTCode { - const char - *name; + const char* name; + long long length; - ssize_t - length; - - const char - *description; + const char* description; } PICTCode; - - typedef struct { - short - top, - left, - bottom, - right; + short top; + short left; + short bottom; + short right; } PICTrectangle; - - typedef struct { - short - version, - pack_type; + short version; + short pack_type; - size_t - pack_size, - horizontal_resolution, - vertical_resolution; + size_t pack_size; + size_t horizontal_resolution; + size_t vertical_resolution; - short - pixel_type, - bits_per_pixel, - component_count, - component_size; + short pixel_type; + short bits_per_pixel; + short component_count; + short component_size; - size_t - plane_bytes, - table, - reserved; + size_t plane_bytes; + size_t table; + size_t reserved; } PICTPixmap; typedef struct { - size_t - width, - height; + size_t width; + size_t height; - ssize_t - x, - y; + long long x; + long long y; } RectangleInfo; typedef struct _NexusInfo { - RectangleInfo - region; - - size_t - length; - - unsigned char - *pixels; - - int - authentic_pixel_cache; - - size_t - signature; - - struct _NexusInfo - *virtual_nexus; + RectangleInfo region; + size_t length; + unsigned char* pixels; + int authentic_pixel_cache; + size_t signature; + struct _NexusInfo* virtual_nexus; } NexusInfo; - typedef struct _GeometryInfo { - double - rho, - sigma, - xi, - psi, - chi; + double rho; + double sigma; + double xi; + double psi; + double chi; } GeometryInfo; typedef enum { - UndefinedChannel = 0x0000, - RedChannel = 0x0001, - GrayChannel = 0x0001, - CyanChannel = 0x0001, - LChannel = 0x0001, - GreenChannel = 0x0002, - MagentaChannel = 0x0002, - aChannel = 0x0002, - BlueChannel = 0x0004, - bChannel = 0x0002, - YellowChannel = 0x0004, - BlackChannel = 0x0008, - AlphaChannel = 0x0010, - OpacityChannel = 0x0010, - IndexChannel = 0x0020, /* Color Index Table? */ - ReadMaskChannel = 0x0040, /* Pixel is Not Readable? */ - WriteMaskChannel = 0x0080, /* Pixel is Write Protected? */ - MetaChannel = 0x0100, /* not used */ - CompositeMaskChannel = 0x0200, /* SVG mask */ - CompositeChannels = 0x001F, - AllChannels = 0X7FFFFFF, - /* - Special purpose channel types. - FUTURE: are these needed any more - they are more like hacks - SyncChannels for example is NOT a real channel but a 'flag' - It really says -- "User has not defined channels" - Though it does have extra meaning in the "-auto-level" operator - */ - TrueAlphaChannel = 0x0100, /* extract actual alpha channel from opacity */ - RGBChannels = 0x0200, /* set alpha from grayscale mask in RGB */ - GrayChannels = 0x0400, - SyncChannels = 0x20000, /* channels modified as a single unit */ - DefaultChannels = AllChannels + UndefinedChannel = 0x0000, + RedChannel = 0x0001, + GrayChannel = 0x0001, + CyanChannel = 0x0001, + LChannel = 0x0001, + GreenChannel = 0x0002, + MagentaChannel = 0x0002, + aChannel = 0x0002, + BlueChannel = 0x0004, + bChannel = 0x0002, + YellowChannel = 0x0004, + BlackChannel = 0x0008, + AlphaChannel = 0x0010, + OpacityChannel = 0x0010, + IndexChannel = 0x0020, /* Color Index Table? */ + ReadMaskChannel = 0x0040, /* Pixel is Not Readable? */ + WriteMaskChannel = 0x0080, /* Pixel is Write Protected? */ + MetaChannel = 0x0100, /* not used */ + CompositeMaskChannel = 0x0200, /* SVG mask */ + CompositeChannels = 0x001F, + AllChannels = 0X7FFFFFF, + /* + Special purpose channel types. + FUTURE: are these needed any more - they are more like hacks + SyncChannels for example is NOT a real channel but a 'flag' + It really says -- "User has not defined channels" + Though it does have extra meaning in the "-auto-level" operator + */ + TrueAlphaChannel = 0x0100, /* extract actual alpha channel from opacity */ + RGBChannels = 0x0200, /* set alpha from grayscale mask in RGB */ + GrayChannels = 0x0400, + SyncChannels = 0x20000, /* channels modified as a single unit */ + DefaultChannels = AllChannels } ChannelType; typedef enum { - ReadMode, - WriteMode, - IOMode, - PersistMode + ReadMode, + WriteMode, + IOMode, + PersistMode } MapMode; typedef enum { - UndefinedClass, - DirectClass, - PseudoClass + UndefinedClass, + DirectClass, + PseudoClass } ClassType; typedef enum { - UndefinedColorspace, - CMYColorspace, /* negated linear RGB colorspace */ - CMYKColorspace, /* CMY with Black separation */ - GRAYColorspace, /* Single Channel greyscale (non-linear) image */ - HCLColorspace, - HCLpColorspace, - HSBColorspace, - HSIColorspace, - HSLColorspace, - HSVColorspace, /* alias for HSB */ - HWBColorspace, - LabColorspace, - LCHColorspace, /* alias for LCHuv */ - LCHabColorspace, /* Cylindrical (Polar) Lab */ - LCHuvColorspace, /* Cylindrical (Polar) Luv */ - LogColorspace, - LMSColorspace, - LuvColorspace, - OHTAColorspace, - Rec601YCbCrColorspace, - Rec709YCbCrColorspace, - RGBColorspace, /* Linear RGB colorspace */ - scRGBColorspace, /* ??? */ - sRGBColorspace, /* Default: non-linear sRGB colorspace */ - TransparentColorspace, - xyYColorspace, - XYZColorspace, /* IEEE Color Reference colorspace */ - YCbCrColorspace, - YCCColorspace, - YDbDrColorspace, - YIQColorspace, - YPbPrColorspace, - YUVColorspace, - LinearGRAYColorspace, /* Single Channel greyscale (linear) image */ - JzazbzColorspace, - DisplayP3Colorspace, - Adobe98Colorspace, - ProPhotoColorspace, - OklabColorspace, - OklchColorspace + UndefinedColorspace, + CMYColorspace, /* negated linear RGB colorspace */ + CMYKColorspace, /* CMY with Black separation */ + GRAYColorspace, /* Single Channel greyscale (non-linear) image */ + HCLColorspace, + HCLpColorspace, + HSBColorspace, + HSIColorspace, + HSLColorspace, + HSVColorspace, /* alias for HSB */ + HWBColorspace, + LabColorspace, + LCHColorspace, /* alias for LCHuv */ + LCHabColorspace, /* Cylindrical (Polar) Lab */ + LCHuvColorspace, /* Cylindrical (Polar) Luv */ + LogColorspace, + LMSColorspace, + LuvColorspace, + OHTAColorspace, + Rec601YCbCrColorspace, + Rec709YCbCrColorspace, + RGBColorspace, /* Linear RGB colorspace */ + scRGBColorspace, /* ??? */ + sRGBColorspace, /* Default: non-linear sRGB colorspace */ + TransparentColorspace, + xyYColorspace, + XYZColorspace, /* IEEE Color Reference colorspace */ + YCbCrColorspace, + YCCColorspace, + YDbDrColorspace, + YIQColorspace, + YPbPrColorspace, + YUVColorspace, + LinearGRAYColorspace, /* Single Channel greyscale (linear) image */ + JzazbzColorspace, + DisplayP3Colorspace, + Adobe98Colorspace, + ProPhotoColorspace, + OklabColorspace, + OklchColorspace } ColorspaceType; typedef enum { - UndefinedPixelTrait = 0x000000, - CopyPixelTrait = 0x000001, - UpdatePixelTrait = 0x000002, - BlendPixelTrait = 0x000004 + UndefinedPixelTrait = 0x000000, + CopyPixelTrait = 0x000001, + UpdatePixelTrait = 0x000002, + BlendPixelTrait = 0x000004 } PixelTrait; typedef enum { - UndefinedPixelChannel = 0, - RedPixelChannel = 0, - CyanPixelChannel = 0, - GrayPixelChannel = 0, - LPixelChannel = 0, - LabelPixelChannel = 0, - YPixelChannel = 0, - aPixelChannel = 1, - GreenPixelChannel = 1, - MagentaPixelChannel = 1, - CbPixelChannel = 1, - bPixelChannel = 2, - BluePixelChannel = 2, - YellowPixelChannel = 2, - CrPixelChannel = 2, - BlackPixelChannel = 3, - AlphaPixelChannel = 4, - IndexPixelChannel = 5, - ReadMaskPixelChannel = 6, - WriteMaskPixelChannel = 7, - MetaPixelChannel = 8, /* deprecated */ - CompositeMaskPixelChannel = 9, - MetaPixelChannels = 10, - IntensityPixelChannel = 64, /* ???? */ - CompositePixelChannel = 64, /* ???? */ - SyncPixelChannel = 65 /* not a real channel */ + UndefinedPixelChannel = 0, + RedPixelChannel = 0, + CyanPixelChannel = 0, + GrayPixelChannel = 0, + LPixelChannel = 0, + LabelPixelChannel = 0, + YPixelChannel = 0, + aPixelChannel = 1, + GreenPixelChannel = 1, + MagentaPixelChannel = 1, + CbPixelChannel = 1, + bPixelChannel = 2, + BluePixelChannel = 2, + YellowPixelChannel = 2, + CrPixelChannel = 2, + BlackPixelChannel = 3, + AlphaPixelChannel = 4, + IndexPixelChannel = 5, + ReadMaskPixelChannel = 6, + WriteMaskPixelChannel = 7, + MetaPixelChannel = 8, /* deprecated */ + CompositeMaskPixelChannel = 9, + MetaPixelChannels = 10, + IntensityPixelChannel = 64, /* ???? */ + CompositePixelChannel = 64, /* ???? */ + SyncPixelChannel = 65 /* not a real channel */ } PixelChannel; typedef struct { - PixelChannel - channel; - - PixelTrait - traits; - - ssize_t - offset; + PixelChannel channel; + PixelTrait traits; + long long offset; } PixelChannelMap; typedef struct { - ClassType - storage_class; + ClassType storage_class; - ColorspaceType - colorspace; + ColorspaceType colorspace; - PixelTrait - alpha_trait; + PixelTrait alpha_trait; - double - fuzz; + double fuzz; - size_t - depth, - count; + size_t depth; + size_t count; - double - red, - green, - blue, - black, - alpha, - index; + double red; + double green; + double blue; + double black; + double alpha; + double index; } PixelInfo; typedef struct { - ClassType - storage_class; + ClassType storage_class; + ColorspaceType colorspace; + ChromaticityInfo chromaticity; + int m_pctVersion; - ColorspaceType - colorspace; + size_t m_nHeight; + size_t m_nWidth; + size_t m_ndepth; + size_t m_nPixelsSize; + size_t colors; - ChromaticityInfo - chromaticity; + SplayTreeInfo* profiles; + SplayTreeInfo* artifacts; - int - m_pctVersion; + double fuzz; - size_t - m_nHeight, - m_nWidth, - m_ndepth, - m_nPixelsSize, - colors; + unsigned char* ppixels; - SplayTreeInfo - *profiles, - *artifacts; + double resolutionX; + double resolutionY; + double gamma; - double - fuzz; + ImageType type; - unsigned char - *ppixels; + PixelInfo background_color; + PixelInfo* colormap; - double - resolutionX, - resolutionY, - gamma; + PixelTrait alpha_trait; - ImageType - type; + NexusInfo* nexus; - PixelInfo - background_color, - *colormap; + PixelChannelMap* channel_map; - PixelTrait - alpha_trait; + PixelTrait mask_trait; - NexusInfo - *nexus; + int taint; - PixelChannelMap - *channel_map; + void* cache; - PixelTrait - mask_trait; + size_t number_channels; - int - taint; - - void - *cache; - - size_t - number_channels; - - char - error[256]; + char error[256]; }ImagePICT; int DecodePICT(FILE* hFile, ImagePICT* image); void AquireImage(ImagePICT* image); -ImagePICT *DestroyImage(ImagePICT *image); +ImagePICT* DestroyImage(ImagePICT* image); #endif // PIC_H From 36c2e3dd22d921be8e42beda6fdec0c2265dc4f3 Mon Sep 17 00:00:00 2001 From: "Elena.Subbotina" Date: Mon, 11 Dec 2023 14:42:13 +0300 Subject: [PATCH 2/6] . --- DesktopEditor/raster/PICT/pic.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/DesktopEditor/raster/PICT/pic.cpp b/DesktopEditor/raster/PICT/pic.cpp index 749b829cf1..0e05e06ed4 100644 --- a/DesktopEditor/raster/PICT/pic.cpp +++ b/DesktopEditor/raster/PICT/pic.cpp @@ -354,8 +354,7 @@ StringInfo *AcquireStringInfo(const size_t length) char *CloneString(char **destination,const char *source) { - size_t - length; + size_t length; if (source == (const char *) NULL) { @@ -365,34 +364,34 @@ char *CloneString(char **destination,const char *source) } if (*destination == (char *) NULL) { - *destination=(char*) malloc((strlen(source) + 4096) * sizeof (*destination)); - (void) memcpy(destination,source,strlen(source)*sizeof(**destination)); - destination[strlen(source)]='\0'; + *destination=(char*) malloc((strlen(source) + 4096)/* * sizeof (*destination)*/); + + memcpy(*destination,source,strlen(source)/**sizeof(**destination)*/); + (*destination)[strlen(source)]='\0'; return(*destination); } length=strlen(source); if (~length < 4096) return NULL; free(*destination); - *destination = (char*) malloc((length+4096)*sizeof (**destination)); + *destination = (char*) malloc((length+4096)/**sizeof (**destination)*/); if (*destination == (char *) NULL) return NULL; if (length != 0) - (void) memcpy(*destination,source,length*sizeof(**destination)); + memcpy(*destination,source,length/**sizeof(**destination)*/); (*destination)[length]='\0'; return(*destination); } StringInfo *CloneStringInfo(const StringInfo *string_info) { - StringInfo - *clone_info; + StringInfo *clone_info; clone_info=AcquireStringInfo(string_info->length); - (void) CloneString(&clone_info->path,string_info->path); - (void) CloneString(&clone_info->name,string_info->name); + CloneString(&clone_info->path,string_info->path); + CloneString(&clone_info->name,string_info->name); if (string_info->length != 0) - (void) memcpy(clone_info->datum,string_info->datum,string_info->length+1); + memcpy(clone_info->datum,string_info->datum,string_info->length+1); return(clone_info); } From 5c52d729320bf121b551cd3fded1bb18dc7202f1 Mon Sep 17 00:00:00 2001 From: Kamil Kerimov Date: Thu, 14 Dec 2023 17:44:56 +0500 Subject: [PATCH 3/6] Fix duration serialization --- .../Converter/pptx_animation_context.cpp | 41 ++++++++++++------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/OdfFile/Reader/Converter/pptx_animation_context.cpp b/OdfFile/Reader/Converter/pptx_animation_context.cpp index c6e97b3298..31e191a780 100644 --- a/OdfFile/Reader/Converter/pptx_animation_context.cpp +++ b/OdfFile/Reader/Converter/pptx_animation_context.cpp @@ -653,6 +653,21 @@ namespace oox { return impl_->root_animation_element_; } + static _CP_OPT(std::wstring) serialize_duration(const _CP_OPT(int) duration) + { + _CP_OPT(std::wstring) res = boost::none; + + if (duration) + { + if (*duration == -1) + res = L"indefinite"; + else + res = std::to_wstring(duration.value()); + } + + return res; + } + void pptx_animation_context::Impl::_par_animation::serialize(std::wostream& strm) { CP_XML_WRITER(strm) @@ -727,8 +742,10 @@ namespace oox { CP_XML_ATTR(L"nodeType", PresentationNodeType.value()); CP_XML_ATTR(L"dur", L"indefinite"); } - else if (Duration) - CP_XML_ATTR(L"dur", Duration.value()); + else + { + CP_XML_ATTR_OPT(L"dur", serialize_duration(Duration)); + } if (TargetEl) { @@ -796,9 +813,9 @@ namespace oox { { CP_XML_NODE(L"p:cTn") { - CP_XML_ATTR_OPT(L"dur" , Duration); - CP_XML_ATTR_OPT(L"fill" , Fill); - + CP_XML_ATTR_OPT(L"dur", serialize_duration(Duration)); + CP_XML_ATTR_OPT(L"fill", Fill); + if (Delay) { CP_XML_NODE(L"p:stCondLst") @@ -861,7 +878,7 @@ namespace oox { { CP_XML_NODE(L"p:cTn") { - CP_XML_ATTR(L"dur", Duration.value()); + CP_XML_ATTR_OPT(L"dur", serialize_duration(Duration)); } } if (ShapeID) @@ -926,8 +943,7 @@ namespace oox { CP_XML_NODE(L"p:cTn") { - int duration = Duration ? Duration.value() : 1; - CP_XML_ATTR(L"dur", duration); + CP_XML_ATTR_OPT(L"dur", serialize_duration(Duration)); if (AutoReverse) { @@ -1007,8 +1023,7 @@ namespace oox { { CP_XML_NODE(L"p:cTn") { - int duration = Duration ? Duration.value() : 1; - CP_XML_ATTR(L"dur", duration); + CP_XML_ATTR_OPT(L"dur", serialize_duration(Duration)); CP_XML_ATTR(L"fill", L"hold"); CP_XML_NODE(L"p:stCondLst") @@ -1065,8 +1080,7 @@ namespace oox { { CP_XML_NODE(L"p:cTn") { - int duration = Duration ? Duration.value() : 1; - CP_XML_ATTR(L"dur", duration); + CP_XML_ATTR_OPT(L"dur", serialize_duration(Duration)); if (AutoReverse) CP_XML_ATTR(L"autoRev", AutoReverse.value()); if (Fill) CP_XML_ATTR(L"fill", Fill.value()); @@ -1123,8 +1137,7 @@ namespace oox { { CP_XML_NODE(L"p:cTn") { - int duration = Duration ? Duration.value() : 1; - CP_XML_ATTR(L"dur", duration); + CP_XML_ATTR_OPT(L"dur", serialize_duration(Duration)); if (AutoReverse) CP_XML_ATTR(L"autoRev", AutoReverse.value()); if (Fill) CP_XML_ATTR(L"fill", Fill.value()); From 63f6190da858f1e095a71477b91d76ff08116a69 Mon Sep 17 00:00:00 2001 From: Kamil Kerimov Date: Thu, 14 Dec 2023 20:28:40 +0500 Subject: [PATCH 4/6] Fix pptx transition conversion --- .../Reader/Converter/pptx_slide_context.cpp | 1 - OdfFile/Reader/Format/anim_elements.cpp | 18 +++++++++++++----- OdfFile/Writer/Converter/PptxConverter.cpp | 10 ++++++++-- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/OdfFile/Reader/Converter/pptx_slide_context.cpp b/OdfFile/Reader/Converter/pptx_slide_context.cpp index 3b69adf2fb..3a9d5f1845 100644 --- a/OdfFile/Reader/Converter/pptx_slide_context.cpp +++ b/OdfFile/Reader/Converter/pptx_slide_context.cpp @@ -1012,7 +1012,6 @@ void pptx_slide_context::serialize_objects(std::wostream & strm) } } } - process_drawings(); impl_->get_drawings()->serialize(strm); } diff --git a/OdfFile/Reader/Format/anim_elements.cpp b/OdfFile/Reader/Format/anim_elements.cpp index ff4f8c4b7b..7f1b4563b6 100644 --- a/OdfFile/Reader/Format/anim_elements.cpp +++ b/OdfFile/Reader/Format/anim_elements.cpp @@ -1122,7 +1122,7 @@ void anim_transitionFilter::pptx_convert(oox::pptx_conversion_context & Context) } std::wstring filter = convert_filter(); - std::wstring transition = L"in"; + _CP_OPT(std::wstring) transition; _CP_OPT(int) time; size_t shapeId = 0; @@ -1133,8 +1133,7 @@ void anim_transitionFilter::pptx_convert(oox::pptx_conversion_context & Context) if (filter_attlist_.smil_mode_) { - if (filter_attlist_.smil_mode_.value() == L"out") - transition = L"out"; + transition = filter_attlist_.smil_mode_.value(); } if (common_attlist_.smil_target_element_) @@ -1144,8 +1143,8 @@ void anim_transitionFilter::pptx_convert(oox::pptx_conversion_context & Context) animationContext.start_anim_effect(); animationContext.set_anim_effect_filter(filter); - animationContext.set_anim_effect_transition(transition); - if (time) animationContext.set_anim_effect_duration(time.value()); + if(transition) animationContext.set_anim_effect_transition(transition.value()); + if (time) animationContext.set_anim_effect_duration(time.value()); animationContext.set_anim_effect_shape_id(shapeId); animationContext.end_anim_effect(); } @@ -1260,6 +1259,15 @@ void anim_set::pptx_convert(oox::pptx_conversion_context& Context) to_value = L"hidden"; else if (set_attlist_.smil_to_.value() == L"solid") to_value = L"solid"; + + try + { + to_value = std::to_wstring(boost::lexical_cast(set_attlist_.smil_to_.value())); + } + catch (const boost::bad_lexical_cast& e) + { + // Ignore + } } oox::pptx_animation_context& animationContext = Context.get_slide_context().get_animation_context(); diff --git a/OdfFile/Writer/Converter/PptxConverter.cpp b/OdfFile/Writer/Converter/PptxConverter.cpp index f600b8b7b3..2db929d366 100644 --- a/OdfFile/Writer/Converter/PptxConverter.cpp +++ b/OdfFile/Writer/Converter/PptxConverter.cpp @@ -791,7 +791,7 @@ void PptxConverter::convert(PPTX::Logic::AnimEffect* oox_anim_effect) std::wstring filter = *oox_anim_effect->filter; std::wstring subtype = L""; - smil_transition_type odfType; + _CP_OPT(smil_transition_type) odfType = boost::none; std::wstring odfSubtype = L""; bool odfReversed = false; @@ -912,13 +912,19 @@ void PptxConverter::convert(PPTX::Logic::AnimEffect* oox_anim_effect) else if (subtype == L"down") { odfReversed = true; odfSubtype = L"fromBottom"; } else if (subtype == L"up") { odfReversed = false; odfSubtype = L"fromTop"; } } + else if (filter == L"image") + { + odfType = boost::none; + } else { odfType = smil_transition_type::fade; odfReversed = false; } - odp_context->current_slide().set_anim_transition_filter_type(odfType); + if(odfType) + odp_context->current_slide().set_anim_transition_filter_type(odfType.value()); + if(!odfSubtype.empty()) odp_context->current_slide().set_anim_transition_filter_subtype(odfSubtype); if(odfReversed) From f8c664daefe40ef3954b5cb927b4e0e24c42a5de Mon Sep 17 00:00:00 2001 From: Kamil Kerimov Date: Thu, 14 Dec 2023 20:34:22 +0500 Subject: [PATCH 5/6] Fix smil attribute name conversion --- OdfFile/DataTypes/smil_attributename.cpp | 48 ++++++++++++------------ OdfFile/Reader/Format/anim_elements.cpp | 3 ++ 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/OdfFile/DataTypes/smil_attributename.cpp b/OdfFile/DataTypes/smil_attributename.cpp index 92c7e67d9f..0e7942f529 100644 --- a/OdfFile/DataTypes/smil_attributename.cpp +++ b/OdfFile/DataTypes/smil_attributename.cpp @@ -77,30 +77,30 @@ namespace cpdoccore { namespace odf_types { boost::algorithm::erase_all(tmp, L"-"); if (tmp == L"charcolor") return smil_attribute_name(charColor); - else if (Str == L"charfontname") return smil_attribute_name(charFontName); - else if (Str == L"charheight") return smil_attribute_name(charHeight); - else if (Str == L"charposture") return smil_attribute_name(charPosture); - else if (Str == L"charunderline") return smil_attribute_name(charUnderline); - else if (Str == L"charweight") return smil_attribute_name(charWeight); - else if (Str == L"color") return smil_attribute_name(color); - else if (Str == L"fillcolor") return smil_attribute_name(fillColor); - else if (Str == L"fillstyle") return smil_attribute_name(fillStyle); - else if (Str == L"fillon") return smil_attribute_name(fillOn); - else if (Str == L"height") return smil_attribute_name(height); - else if (Str == L"linecolor") return smil_attribute_name(lineColor); - else if (Str == L"linestyle") return smil_attribute_name(lineStyle); - else if (Str == L"opacity") return smil_attribute_name(opacity); - else if (Str == L"stroke") return smil_attribute_name(stroke); - else if (Str == L"strokecolor") return smil_attribute_name(strokeColor); - else if (Str == L"rotate") return smil_attribute_name(rotate); - else if (Str == L"skewx") return smil_attribute_name(skewX); - else if (Str == L"skewx") return smil_attribute_name(skewY); - else if (Str == L"transform") return smil_attribute_name(transform); - else if (Str == L"visibility") return smil_attribute_name(visibility); - else if (Str == L"width") return smil_attribute_name(width); - else if (Str == L"x") return smil_attribute_name(x); - else if (Str == L"y") return smil_attribute_name(y); - else if (Str == L"dim") return smil_attribute_name(dim); + else if (tmp == L"charfontname") return smil_attribute_name(charFontName); + else if (tmp == L"charheight") return smil_attribute_name(charHeight); + else if (tmp == L"charposture") return smil_attribute_name(charPosture); + else if (tmp == L"charunderline") return smil_attribute_name(charUnderline); + else if (tmp == L"charweight") return smil_attribute_name(charWeight); + else if (tmp == L"color") return smil_attribute_name(color); + else if (tmp == L"fillcolor") return smil_attribute_name(fillColor); + else if (tmp == L"fillstyle") return smil_attribute_name(fillStyle); + else if (tmp == L"fillon") return smil_attribute_name(fillOn); + else if (tmp == L"height") return smil_attribute_name(height); + else if (tmp == L"linecolor") return smil_attribute_name(lineColor); + else if (tmp == L"linestyle") return smil_attribute_name(lineStyle); + else if (tmp == L"opacity") return smil_attribute_name(opacity); + else if (tmp == L"stroke") return smil_attribute_name(stroke); + else if (tmp == L"strokecolor") return smil_attribute_name(strokeColor); + else if (tmp == L"rotate") return smil_attribute_name(rotate); + else if (tmp == L"skewx") return smil_attribute_name(skewX); + else if (tmp == L"skewx") return smil_attribute_name(skewY); + else if (tmp == L"transform") return smil_attribute_name(transform); + else if (tmp == L"visibility") return smil_attribute_name(visibility); + else if (tmp == L"width") return smil_attribute_name(width); + else if (tmp == L"x") return smil_attribute_name(x); + else if (tmp == L"y") return smil_attribute_name(y); + else if (tmp == L"dim") return smil_attribute_name(dim); return smil_attribute_name(none); } diff --git a/OdfFile/Reader/Format/anim_elements.cpp b/OdfFile/Reader/Format/anim_elements.cpp index 7f1b4563b6..df1f341c42 100644 --- a/OdfFile/Reader/Format/anim_elements.cpp +++ b/OdfFile/Reader/Format/anim_elements.cpp @@ -286,11 +286,14 @@ static std::wstring pptx_convert_smil_attribute_name(const odf_types::smil_attri case smil_attribute_name::fill: return L"fill.type"; case smil_attribute_name::fillColor: return L"fillcolor"; case smil_attribute_name::fillStyle: return L""; + case smil_attribute_name::fillOn: return L"fill.on"; case smil_attribute_name::height: return L"ppt_h"; case smil_attribute_name::lineColor: return L""; case smil_attribute_name::lineStyle: return L""; case smil_attribute_name::opacity: return L"style.opacity"; case smil_attribute_name::rotate: return L"r"; + case smil_attribute_name::stroke: return L"stroke.on"; + case smil_attribute_name::strokeColor: return L"stroke.color"; case smil_attribute_name::skewX: return L"xshear"; case smil_attribute_name::skewY: return L""; case smil_attribute_name::visibility: return L"style.visibility"; From 607d32e32b90acf11ff34a36c45cb7fa924ec4ce Mon Sep 17 00:00:00 2001 From: Kamil Kerimov Date: Fri, 15 Dec 2023 14:01:10 +0500 Subject: [PATCH 6/6] Fix bug #65362 --- OdfFile/DataTypes/smil_attributename.cpp | 1 + .../Converter/pptx_animation_context.cpp | 175 ++++++++++++++++-- .../Reader/Converter/pptx_animation_context.h | 27 ++- OdfFile/Reader/Format/anim_elements.cpp | 135 ++++++++++---- 4 files changed, 292 insertions(+), 46 deletions(-) diff --git a/OdfFile/DataTypes/smil_attributename.cpp b/OdfFile/DataTypes/smil_attributename.cpp index 0e7942f529..bf819b228e 100644 --- a/OdfFile/DataTypes/smil_attributename.cpp +++ b/OdfFile/DataTypes/smil_attributename.cpp @@ -83,6 +83,7 @@ namespace cpdoccore { namespace odf_types { else if (tmp == L"charunderline") return smil_attribute_name(charUnderline); else if (tmp == L"charweight") return smil_attribute_name(charWeight); else if (tmp == L"color") return smil_attribute_name(color); + else if (tmp == L"fill") return smil_attribute_name(fill); else if (tmp == L"fillcolor") return smil_attribute_name(fillColor); else if (tmp == L"fillstyle") return smil_attribute_name(fillStyle); else if (tmp == L"fillon") return smil_attribute_name(fillOn); diff --git a/OdfFile/Reader/Converter/pptx_animation_context.cpp b/OdfFile/Reader/Converter/pptx_animation_context.cpp index 31e191a780..d32a3aa749 100644 --- a/OdfFile/Reader/Converter/pptx_animation_context.cpp +++ b/OdfFile/Reader/Converter/pptx_animation_context.cpp @@ -33,6 +33,7 @@ #include "pptx_animation_context.h" #include +#include #include "../../DataTypes/clockvalue.h" @@ -263,6 +264,11 @@ namespace oox { impl_->set_description_->End = value; } + void pptx_animation_context::set_set_auto_rev(const std::wstring& value) + { + impl_->set_description_->AutoRev = value; + } + void pptx_animation_context::set_set_fill(const std::wstring& value) { impl_->set_description_->Fill = value; @@ -463,6 +469,11 @@ namespace oox { impl_->anim_clr_description_->ColorSpace = value; } + void pptx_animation_context::set_animate_color_dir(const std::wstring& value) + { + impl_->anim_clr_description_->Direction = value; + } + void pptx_animation_context::set_animate_color_duration(int value) { impl_->anim_clr_description_->Duration = value; @@ -473,6 +484,16 @@ namespace oox { impl_->anim_clr_description_->Delay = value; } + void pptx_animation_context::set_animate_color_fill(const std::wstring& value) + { + impl_->anim_clr_description_->Fill = value; + } + + void pptx_animation_context::set_animate_color_auto_rev(bool value) + { + impl_->anim_clr_description_->AutoRev = value; + } + void pptx_animation_context::set_animate_color_attribute_name(const std::wstring& value) { impl_->anim_clr_description_->AttributeName = value; @@ -483,6 +504,55 @@ namespace oox { impl_->anim_clr_description_->ToValue = value; } + void pptx_animation_context::set_animate_color_by_value(const std::wstring& value) + { + impl_->anim_clr_description_->ByValue = pptx_animation_context::Impl::_anim_clr::color(); + + if (boost::algorithm::starts_with(value, L"#")) + { + if (value.size() != std::wstring(L"#rrggbb").size()) + return; + + const std::wstring str = value.substr(1); // Remove # character + + int r = 0; + int g = 0; + int b = 0; + + std::wistringstream(str.substr(0, 2)) >> std::hex >> r; + std::wistringstream(str.substr(2, 2)) >> std::hex >> g; + std::wistringstream(str.substr(4, 2)) >> std::hex >> b; + + impl_->anim_clr_description_->ByValue->type_ = pptx_animation_context::Impl::_anim_clr::color::rgb; + impl_->anim_clr_description_->ByValue->v1 = r; + impl_->anim_clr_description_->ByValue->v2 = g; + impl_->anim_clr_description_->ByValue->v3 = b; + } + else if (boost::algorithm::starts_with(value, L"hsl")) + { + std::wstring str = value; + boost::algorithm::erase_all(str, L"hsl"); + boost::algorithm::erase_all(str, L"("); + boost::algorithm::erase_all(str, L")"); + boost::algorithm::erase_all(str, L"%"); + std::vector arr; + boost::algorithm::split(arr, str, boost::is_any_of(",")); + + int h = 0; + int s = 0; + int l = 0; + + std::wistringstream(arr[0]) >> h; + std::wistringstream(arr[1]) >> s; + std::wistringstream(arr[2]) >> l; + + impl_->anim_clr_description_->ByValue->type_ = pptx_animation_context::Impl::_anim_clr::color::hsl; + impl_->anim_clr_description_->ByValue->v1 = h * 60000; + impl_->anim_clr_description_->ByValue->v2 = s * 1000; + impl_->anim_clr_description_->ByValue->v3 = l * 1000; + } + } + void pptx_animation_context::set_animate_color_shape_id(size_t value) { impl_->anim_clr_description_->ShapeID = value; @@ -525,11 +595,21 @@ namespace oox { impl_->anim_scale_description_->To = Impl::_anim_scale::vec2(x, y); } + void pptx_animation_context::set_animate_scale_by(int x, int y) + { + impl_->anim_scale_description_->By = Impl::_anim_scale::vec2(x, y); + } + void pptx_animation_context::set_animate_scale_delay(const std::wstring& value) { impl_->anim_scale_description_->Delay = value; } + void pptx_animation_context::set_animate_scale_attribute_name(const std::wstring& value) + { + impl_->anim_scale_description_->AttributeName = value; + } + void pptx_animation_context::set_animate_scale_auto_reverse(bool value) { impl_->anim_scale_description_->AutoReverse = value; @@ -567,6 +647,11 @@ namespace oox { impl_->anim_rotate_description_->By = value; } + void pptx_animation_context::set_animate_rotate_attribute_name(const std::wstring& value) + { + impl_->anim_rotate_description_->AttributeName = value; + } + void pptx_animation_context::set_animate_rotate_delay(const std::wstring& value) { impl_->anim_rotate_description_->Delay = value; @@ -815,6 +900,7 @@ namespace oox { { CP_XML_ATTR_OPT(L"dur", serialize_duration(Duration)); CP_XML_ATTR_OPT(L"fill", Fill); + CP_XML_ATTR_OPT(L"autoRev", AutoRev); if (Delay) { @@ -837,9 +923,9 @@ namespace oox { } } - CP_XML_NODE(L"p:attrNameLst") + if (AttributeName) { - if (AttributeName) + CP_XML_NODE(L"p:attrNameLst") { CP_XML_NODE(L"p:attrName") { @@ -848,9 +934,9 @@ namespace oox { } } } - CP_XML_NODE(L"p:to") + if (ToValue) { - if (ToValue) + CP_XML_NODE(L"p:to") { CP_XML_NODE(L"p:strVal") { @@ -1017,18 +1103,20 @@ namespace oox { { CP_XML_NODE(L"p:animClr") { - if (ColorSpace) CP_XML_ATTR(L"clrSpc", ColorSpace.value()); + CP_XML_ATTR_OPT(L"clrSpc", ColorSpace); CP_XML_NODE(L"p:cBhvr") { CP_XML_NODE(L"p:cTn") { CP_XML_ATTR_OPT(L"dur", serialize_duration(Duration)); - CP_XML_ATTR(L"fill", L"hold"); + CP_XML_ATTR_OPT(L"fill", Fill); + CP_XML_ATTR_OPT(L"autoRev", AutoRev); + CP_XML_ATTR_OPT(L"dir", Direction); - CP_XML_NODE(L"p:stCondLst") + if (Delay) { - if (Delay) + CP_XML_NODE(L"p:stCondLst") { CP_XML_NODE(L"p:cond") { @@ -1045,9 +1133,9 @@ namespace oox { CP_XML_ATTR(L"spid", shapeID); } } - CP_XML_NODE(L"p:attrNameLst") + if (AttributeName) { - if (AttributeName) + CP_XML_NODE(L"p:attrNameLst") { CP_XML_NODE(L"p:attrName") { @@ -1056,9 +1144,9 @@ namespace oox { } } } - CP_XML_NODE(L"p:to") + if (ToValue) { - if (ToValue) + CP_XML_NODE(L"p:to") { CP_XML_NODE(L"a:srgbClr") { @@ -1066,6 +1154,38 @@ namespace oox { } } } + + if (ByValue) + { + CP_XML_NODE(L"p:by") + { + switch (ByValue->type_) + { + case color::rgb: + { + CP_XML_NODE(L"a:srgbClr") + { + std::wstringstream ss; + ss << std::hex + << ByValue->v1 + << ByValue->v2 + << ByValue->v3; + + CP_XML_ATTR(L"val", ss.str()); + } + } break; + case color::hsl: + { + CP_XML_NODE(L"p:hsl") + { + CP_XML_ATTR(L"h", ByValue->v1); + CP_XML_ATTR(L"s", ByValue->v2); + CP_XML_ATTR(L"l", ByValue->v3); + } + } break; + } + } + } } } } @@ -1102,6 +1222,17 @@ namespace oox { CP_XML_ATTR(L"spid", shapeID); } } + + if (AttributeName) + { + CP_XML_NODE(L"p:attrNameLst") + { + CP_XML_NODE(L"p:attrName") + { + CP_XML_STREAM() << AttributeName.value(); + } + } + } } if (From) @@ -1121,6 +1252,15 @@ namespace oox { CP_XML_ATTR(L"y", To->y); } } + + if (By) + { + CP_XML_NODE(L"p:by") + { + CP_XML_ATTR(L"x", By->x); + CP_XML_ATTR(L"y", By->y); + } + } } } } @@ -1159,6 +1299,17 @@ namespace oox { CP_XML_ATTR(L"spid", shapeID); } } + + if (AttributeName) + { + CP_XML_NODE(L"p:attrNameLst") + { + CP_XML_NODE(L"p:attrName") + { + CP_XML_STREAM() << AttributeName.value(); + } + } + } } } } diff --git a/OdfFile/Reader/Converter/pptx_animation_context.h b/OdfFile/Reader/Converter/pptx_animation_context.h index 1b874274a3..d2a6897f57 100644 --- a/OdfFile/Reader/Converter/pptx_animation_context.h +++ b/OdfFile/Reader/Converter/pptx_animation_context.h @@ -106,6 +106,7 @@ namespace oox { _CP_OPT(int) Duration; // in ms _CP_OPT(std::wstring) Delay; _CP_OPT(std::wstring) End; + _CP_OPT(std::wstring) AutoRev; _CP_OPT(std::wstring) Fill; _CP_OPT(size_t) ShapeID; _CP_OPT(std::wstring) AttributeName; @@ -150,6 +151,18 @@ namespace oox { typedef shared_ptr<_anim_clr>::Type _anim_clr_ptr; struct _anim_clr : _animation_element { + struct color + { + enum type + { + rgb, + hsl + } type_; + + int v1, v2, v3; + }; + + _CP_OPT(std::wstring) PresentationNodeType; _CP_OPT(std::wstring) Direction; _CP_OPT(std::wstring) Restart; @@ -158,10 +171,12 @@ namespace oox { _CP_OPT(std::wstring) End; _CP_OPT(std::wstring) Fill; + _CP_OPT(bool) AutoRev; _CP_OPT(size_t) ShapeID; _CP_OPT(std::wstring) AttributeName; _CP_OPT(std::wstring) Delay; _CP_OPT(std::wstring) ToValue; + _CP_OPT(color) ByValue; _CP_OPT(std::wstring) ColorSpace; void serialize(std::wostream& strm) override; @@ -216,8 +231,9 @@ namespace oox { _CP_OPT(std::wstring) Fill; _CP_OPT(vec2) From; _CP_OPT(vec2) To; - //_CP_OPT(std::wstring) By; + _CP_OPT(vec2) By; _CP_OPT(std::wstring) Delay; + _CP_OPT(std::wstring) AttributeName; _CP_OPT(bool) AutoReverse; void serialize(std::wostream& strm) override; @@ -231,6 +247,7 @@ namespace oox { _CP_OPT(int) Duration; // in ms _CP_OPT(std::wstring) Fill; _CP_OPT(int) By; + _CP_OPT(std::wstring) AttributeName; _CP_OPT(std::wstring) Delay; _CP_OPT(bool) AutoReverse; @@ -299,6 +316,7 @@ namespace oox { void set_set_duration(int value); void set_set_delay(const std::wstring& value); void set_set_end(const std::wstring& value); + void set_set_auto_rev(const std::wstring& value); void set_set_fill(const std::wstring& value); void set_set_shape_id(size_t value); void set_set_attribute_name(const std::wstring& value); @@ -341,10 +359,14 @@ namespace oox { void start_animate_color(); void set_animate_color_color_space(const std::wstring& value); + void set_animate_color_dir(const std::wstring& value); void set_animate_color_duration(int value); void set_animate_color_delay(const std::wstring& value); + void set_animate_color_fill(const std::wstring& value); + void set_animate_color_auto_rev(bool value); void set_animate_color_attribute_name(const std::wstring& value); void set_animate_color_to_value(const std::wstring& value); + void set_animate_color_by_value(const std::wstring& value); void set_animate_color_shape_id(size_t value); void end_animate_color(); @@ -354,7 +376,9 @@ namespace oox { void set_animate_scale_fill(const std::wstring& value); void set_animate_scale_from(int x, int y); void set_animate_scale_to(int x, int y); + void set_animate_scale_by(int x, int y); void set_animate_scale_delay(const std::wstring& value); + void set_animate_scale_attribute_name(const std::wstring& value); void set_animate_scale_auto_reverse(bool value); void end_animate_scale(); @@ -363,6 +387,7 @@ namespace oox { void set_animate_rotate_duration(int value); void set_animate_rotate_fill(const std::wstring& value); void set_animate_rotate_by(int value); + void set_animate_rotate_attribute_name(const std::wstring& value); void set_animate_rotate_delay(const std::wstring& value); void set_animate_rotate_auto_reverse(bool value); void end_animate_rotate(); diff --git a/OdfFile/Reader/Format/anim_elements.cpp b/OdfFile/Reader/Format/anim_elements.cpp index df1f341c42..9f75680b7e 100644 --- a/OdfFile/Reader/Format/anim_elements.cpp +++ b/OdfFile/Reader/Format/anim_elements.cpp @@ -1213,6 +1213,7 @@ void anim_set::pptx_convert(oox::pptx_conversion_context& Context) _CP_OPT(std::wstring) delay; _CP_OPT(std::wstring) end; _CP_OPT(std::wstring) fill; + _CP_OPT(std::wstring) autoRev; _CP_OPT(std::wstring) attribute_name; _CP_OPT(std::wstring) to_value; size_t shapeID = 0; @@ -1221,6 +1222,9 @@ void anim_set::pptx_convert(oox::pptx_conversion_context& Context) { } + if (common_attlist_.smil_auto_reverse_) + autoRev = common_attlist_.smil_auto_reverse_->get() == true ? L"1" : L"0"; + if (common_attlist_.smil_restart_) { } @@ -1258,18 +1262,24 @@ void anim_set::pptx_convert(oox::pptx_conversion_context& Context) { if (set_attlist_.smil_to_.value() == L"visible") to_value = L"visible"; - else if(set_attlist_.smil_to_.value() == L"hidden") + else if (set_attlist_.smil_to_.value() == L"hidden") to_value = L"hidden"; else if (set_attlist_.smil_to_.value() == L"solid") to_value = L"solid"; - - try + else if (set_attlist_.smil_to_.value() == L"false") + to_value = L"false"; + else if (set_attlist_.smil_to_.value() == L"true") + to_value = L"true"; + else { - to_value = std::to_wstring(boost::lexical_cast(set_attlist_.smil_to_.value())); - } - catch (const boost::bad_lexical_cast& e) - { - // Ignore + try + { + to_value = std::to_wstring(boost::lexical_cast(set_attlist_.smil_to_.value())); + } + catch (const boost::bad_lexical_cast& e) + { + // Ignore + } } } @@ -1281,6 +1291,7 @@ void anim_set::pptx_convert(oox::pptx_conversion_context& Context) if (duration) animationContext.set_set_duration(duration.value()); if (delay) animationContext.set_set_delay(delay.value()); if (end) animationContext.set_set_end(end.value()); + if (autoRev) animationContext.set_set_auto_rev(autoRev.value()); if (fill) animationContext.set_set_fill(fill.value()); if (attribute_name) animationContext.set_set_attribute_name(attribute_name.value()); if (to_value) animationContext.set_set_to_value(to_value.value()); @@ -1353,35 +1364,58 @@ const wchar_t* anim_animate_color::name = L"animateColor"; void anim_animate_color::pptx_convert(oox::pptx_conversion_context& Context) { - _CP_OPT(std::wstring) colorSpace; + _CP_OPT(std::wstring) colorSpace = L"rgb"; _CP_OPT(int) duration; _CP_OPT(std::wstring) delay; _CP_OPT(std::wstring) attributeName; _CP_OPT(std::wstring) toValue; + _CP_OPT(std::wstring) byValue; + _CP_OPT(std::wstring) fill = L"hold"; + _CP_OPT(bool) autoRev = false; + _CP_OPT(std::wstring) dir = L"cw"; // clockwise (cw) size_t shapeID = 0; - colorSpace = L"rgb"; + if (animate_color_attlist_.anim_color_interpolation_) + { + colorSpace = animate_color_attlist_.anim_color_interpolation_.value(); + } + + if (animate_color_attlist_.anim_color_interpolation_direction) + { + if (animate_color_attlist_.anim_color_interpolation_direction.value() == L"clockwise") + dir = L"cw"; + else if (animate_color_attlist_.anim_color_interpolation_direction.value() == L"counter-clockwise") + dir = L"ccw"; + } if (common_attlist_.smil_dur_) duration = common_attlist_.smil_dur_->get_value(); else duration = 1; - if (common_attlist_.smil_begin_) + if (common_attlist_.smil_fill_) { - delay = pptx_convert_smil_begin(common_attlist_.smil_begin_.value()); + bool durationSpecified = common_attlist_.smil_dur_.has_value() || common_attlist_.smil_end_.has_value(); + fill = pptx_convert_smil_fill(common_attlist_.smil_fill_.value(), durationSpecified); } + if (common_attlist_.smil_begin_) + delay = pptx_convert_smil_begin(common_attlist_.smil_begin_.value()); + if (common_attlist_.smil_attribute_name_) - { attributeName = pptx_convert_smil_attribute_name(common_attlist_.smil_attribute_name_.value()); - } if (animate_color_attlist_.smil_to_) { toValue = animate_color_attlist_.smil_to_.value(); - boost::algorithm::erase_all(toValue.value(), L"#"); + boost::erase_all(toValue.value(), L"#"); } + + if (common_attlist_.smil_auto_reverse_) + autoRev = common_attlist_.smil_auto_reverse_->get(); + + if (animate_color_attlist_.smil_by_) + byValue = animate_color_attlist_.smil_by_.value(); if (common_attlist_.smil_target_element_) shapeID = Context.get_slide_context().get_id(common_attlist_.smil_target_element_.value()); @@ -1394,6 +1428,10 @@ void anim_animate_color::pptx_convert(oox::pptx_conversion_context& Context) if (delay) animationContext.set_animate_color_delay(delay.value()); if (attributeName) animationContext.set_animate_color_attribute_name(attributeName.value()); if (toValue) animationContext.set_animate_color_to_value(toValue.value()); + if (byValue) animationContext.set_animate_color_by_value(byValue.value()); + if (autoRev) animationContext.set_animate_color_auto_rev(autoRev.value()); + if (dir) animationContext.set_animate_color_dir(dir.value()); + if (fill) animationContext.set_animate_color_fill(fill.value()); animationContext.set_animate_color_shape_id(shapeID); animationContext.end_animate_color(); } @@ -1525,6 +1563,28 @@ void anim_animate::add_attributes(const xml::attributes_wc_ptr& Attributes) const wchar_t* anim_animate_transform::ns = L"anim"; const wchar_t* anim_animate_transform::name = L"animateTransform"; +static std::vector smil_list_to_oox_vector(const std::wstring& list, int pptx_mulipier) +{ + std::vector oox_list; + std::vector list_str; + boost::split(list_str, list, boost::is_any_of(",")); + + for (const auto& el : list_str) + { + try + { + int num = boost::lexical_cast(el) * pptx_mulipier; + oox_list.push_back(num); + } + catch (boost::bad_lexical_cast e) + { + continue; + } + } + + return oox_list; +} + void anim_animate_transform::pptx_convert(oox::pptx_conversion_context& Context) { size_t shapeID = 0; @@ -1533,6 +1593,7 @@ void anim_animate_transform::pptx_convert(oox::pptx_conversion_context& Context) _CP_OPT(std::wstring) delay; _CP_OPT(bool) autoRev; _CP_OPT(int) by; + _CP_OPT(std::wstring) attributeName; if(common_attlist_.smil_target_element_) shapeID = Context.get_slide_context().get_id(common_attlist_.smil_target_element_.value()); @@ -1545,8 +1606,10 @@ void anim_animate_transform::pptx_convert(oox::pptx_conversion_context& Context) bool durationSpecified = common_attlist_.smil_dur_.has_value() || common_attlist_.smil_end_.has_value(); fill = pptx_convert_smil_fill(common_attlist_.smil_fill_.value(), durationSpecified); } - + if (common_attlist_.smil_attribute_name_) + attributeName = pptx_convert_smil_attribute_name(common_attlist_.smil_attribute_name_.value()); + if (common_attlist_.smil_begin_) delay = pptx_convert_smil_begin(common_attlist_.smil_begin_.value()); @@ -1568,34 +1631,40 @@ void anim_animate_transform::pptx_convert(oox::pptx_conversion_context& Context) if (duration) animationContext.set_animate_scale_duration(duration.value()); if (fill) animationContext.set_animate_scale_fill(fill.value()); if (delay) animationContext.set_animate_scale_delay(delay.value()); + if (attributeName) animationContext.set_animate_scale_attribute_name(attributeName.value()); if (autoRev) animationContext.set_animate_scale_auto_reverse(autoRev.value()); if (animate_transform_attlist_.smil_from_) { const int pptx_mulipier = 100000; - std::vector oox_from; - boost::split(oox_from, animate_transform_attlist_.smil_from_.value(), boost::is_any_of(",")); - if (oox_from.size() >= 2) - { - int x = boost::lexical_cast(oox_from[0]) * pptx_mulipier; - int y = boost::lexical_cast(oox_from[1]) * pptx_mulipier; + const std::vector oox_from = smil_list_to_oox_vector(animate_transform_attlist_.smil_from_.value(), pptx_mulipier); - animationContext.set_animate_scale_from(x, y); - } + if (oox_from.size() >= 2) + animationContext.set_animate_scale_from(oox_from[0], oox_from[1]); + else + _CP_LOG << "[ warning ] cannot convert scale smil:from"; } if (animate_transform_attlist_.smil_to_) { const int pptx_mulipier = 100000; - std::vector oox_to; - boost::split(oox_to, animate_transform_attlist_.smil_to_.value(), boost::is_any_of(",")); - if (oox_to.size() >= 2) - { - int x = boost::lexical_cast(oox_to[0]) * pptx_mulipier; - int y = boost::lexical_cast(oox_to[1]) * pptx_mulipier; + const std::vector oox_to = smil_list_to_oox_vector(animate_transform_attlist_.smil_to_.value(), pptx_mulipier); - animationContext.set_animate_scale_to(x, y); - } + if (oox_to.size() >= 2) + animationContext.set_animate_scale_to(oox_to[0], oox_to[1]); + else + _CP_LOG << "[ warning ] cannot convert scale smil:to"; + } + + if (animate_transform_attlist_.smil_by_) + { + const int pptx_mulipier = 100000; + const std::vector oox_by = smil_list_to_oox_vector(animate_transform_attlist_.smil_by_.value(), pptx_mulipier); + + if (oox_by.size() >= 2) + animationContext.set_animate_scale_by(oox_by[0] + pptx_mulipier, oox_by[1] + pptx_mulipier); + else + _CP_LOG << "[ warning ] cannot convert scale smil:by"; } animationContext.end_animate_scale(); @@ -1623,10 +1692,10 @@ void anim_animate_transform::pptx_convert(oox::pptx_conversion_context& Context) if (delay) animationContext.set_animate_rotate_delay(delay.value()); if (autoRev) animationContext.set_animate_rotate_auto_reverse(autoRev.value()); if (by) animationContext.set_animate_rotate_by(by.value()); + if (attributeName) animationContext.set_animate_rotate_attribute_name(attributeName.value()); animationContext.end_animate_rotate(); break; - break; } } }