diff --git a/Common/base.pri b/Common/base.pri index 9b34fd0a69..b69c26f7ea 100644 --- a/Common/base.pri +++ b/Common/base.pri @@ -52,6 +52,7 @@ mac { # DEFINES core_windows { DEFINES += WIN32 _WIN32 + DEFINES += NOMINMAX } core_win_64 { DEFINES += WIN64 _WIN64 diff --git a/DesktopEditor/graphics/pro/Fonts.h b/DesktopEditor/graphics/pro/Fonts.h index 7a81867231..45548603d2 100644 --- a/DesktopEditor/graphics/pro/Fonts.h +++ b/DesktopEditor/graphics/pro/Fonts.h @@ -558,6 +558,8 @@ namespace NSFonts virtual std::wstring GetFontType() = 0; virtual void SetSubpixelRendering(const bool& hmul, const bool& vmul) = 0; + virtual unsigned int GetNameIndex(const std::wstring& wsName) = 0; + public: static IFontFile* LoadFontFile(CLibrary& library, IFontStream* pStream, int lFaceIndex); }; diff --git a/DesktopEditor/raster/Jp2/J2kFile.cpp b/DesktopEditor/raster/Jp2/J2kFile.cpp index d1067f73d6..35dc34c4e1 100644 --- a/DesktopEditor/raster/Jp2/J2kFile.cpp +++ b/DesktopEditor/raster/Jp2/J2kFile.cpp @@ -387,4 +387,337 @@ namespace Jpeg2000 Image_Destroy(pImage); return bRes; } -} \ No newline at end of file + + void CJ2kFile::ApplyDecoderOptions(void *pParametersV, const std::wstring& sXml) + { + DecoderParams* pParameters = (DecoderParams*)pParametersV; + memset(pParameters, 0, sizeof(DecoderParams)); + pParameters->eLimitDecoding = declimNoLimitation; + pParameters->nReduce = 0; + pParameters->nLayer = 0; + + // TODO: Сделать чтение параметров декодирования + //if (sXml.GetLength() > 0) + //{ + // XmlUtils::CXmlNode oMainNode; + // oMainNode.FromXmlString(sXml); + + // if (-1 != oMainNode.GetName().Find(_T("Jpeg2000-Options"))) + // { + // XmlUtils::CXmlNode oOpenNode; + // if (oMainNode.GetNode(_T("OpenOptions"), oOpenNode)) + // { + // XmlUtils::CXmlNode oCurNode; + // CString sValue; + + // // ReduceFactor + // if (oOpenNode.GetNode(_T("ConvertToRGBA"), oCurNode)) + // { + // sValue = oCurNode.GetAttribute(_T("value"), _T("0")); + // pParameters->bConvertToRGBA = (_wtoi(sValue.GetBuffer()) ? true : false); + // } + + // // ReduceFactor + // if (oOpenNode.GetNode(_T("ReduceFactor"), oCurNode)) + // { + // sValue = oCurNode.GetAttribute(_T("value"), _T("0")); + // pParameters->nReduce = _wtoi(sValue.GetBuffer()); + // } + + // // LayersCount + // if (oOpenNode.GetNode(_T("LayersCount"), oCurNode)) + // { + // sValue = oCurNode.GetAttribute(_T("value"), _T("0")); + // pParameters->nLayer = _wtoi(sValue.GetBuffer()); + // } + // } + // } + //} + } + long CJ2kFile::ApplyEncoderOptions(void *pParametersV, const std::wstring& sXml) + { + EncoderParams* pParameters = (EncoderParams*)pParameters; + int nFormat = 0; // J2k + // Сначала выставляем стандартные значения параметров + memset(pParameters, 0, sizeof(EncoderParams)); + pParameters->nComponentsCount = 3; + pParameters->nResolutionsCount = 6; + pParameters->nCodeBlockHeightInit = 64; + pParameters->nCodeBlockWidthInit = 64; + pParameters->eProgOrder = poLRCP; + pParameters->nROIComponentIndex = -1; // Нет ROI + pParameters->nSubSamplingDx = 1; + pParameters->nSubSamplingDy = 1; + pParameters->bTileSizeOn = false; + pParameters->sComment = (char*)"Manufactured by Online Media Technologies Ltd."; + + // TODO: Сделать чтение параметров кодирования + //if (sXml.GetLength() > 0) + //{ + // XmlUtils::CXmlNode oMainNode; + // oMainNode.FromXmlString(sXml); + + // if (-1 != oMainNode.GetName().Find(_T("Jpeg2000-Options"))) + // { + // XmlUtils::CXmlNode oSaveNode; + // if (oMainNode.GetNode(_T("SaveOptions"), oSaveNode)) + // { + // XmlUtils::CXmlNode oCurNode; + // CString sValue; + + // // ComponentsCount + // if (oSaveNode.GetNode(_T("ComponentsCount"), oCurNode)) + // { + // pParameters->nComponentsCount = XmlUtils::GetInteger(oCurNode.GetAttribute(_T("value"), _T("3"))); + // } + + + // // Format + // if (oSaveNode.GetNode(_T("Format"), oCurNode)) + // { + // sValue = oCurNode.GetAttribute(_T("value"), _T("0")); + // nFormat = _wtoi(sValue.GetBuffer()); + // } + + // // Tile + // if (oSaveNode.GetNode(_T("Tile"), oCurNode)) + // { + // sValue = oCurNode.GetAttribute(_T("width"), _T("32")); + // pParameters->nXTsiz = max(32, _wtoi(sValue.GetBuffer())); + // sValue = oCurNode.GetAttribute(_T("height"), _T("32")); + // pParameters->nYTsiz = max(32, _wtoi(sValue.GetBuffer())); + + // pParameters->bTileSizeOn = true; + + // sValue = oCurNode.GetAttribute(_T("offsetx"), _T("0")); + // pParameters->nXTOsiz = _wtoi(sValue.GetBuffer()); + // sValue = oCurNode.GetAttribute(_T("offsety"), _T("0")); + // pParameters->nYTOsiz = _wtoi(sValue.GetBuffer()); + // } + + // // Resolution + // if (oSaveNode.GetNode(_T("Resolution"), oCurNode)) + // { + // sValue = oCurNode.GetAttribute(_T("levelscount"), _T("6")); + // pParameters->nResolutionsCount = max(1, min(J2K_MAXRLVLS, _wtoi(sValue.GetBuffer()))); + // } + + // // PrecinctDimension + // if (oSaveNode.GetNode(_T("PrecinctDimension"), oCurNode)) + // { + // sValue = oCurNode.GetText(); + // wchar_t *wsTemp = sValue.GetBuffer(); + + // char nSeparateChar = 0; + // int nPrecinctsCount = 0; + // do + // { + // nSeparateChar = 0; + // swscanf(wsTemp, _T("[%d,%d]%c"), &pParameters->anPrecinctWidthInit[nPrecinctsCount], &pParameters->anPrecinctHeightInit[nPrecinctsCount], &nSeparateChar); + // pParameters->nCodingStyle |= 0x01; + // nPrecinctsCount++; + // if (J2K_MAXRLVLS == nPrecinctsCount) + // break; + // wsTemp = wcspbrk(wsTemp, _T("]")) + 2; + // } while (',' == nSeparateChar); + // pParameters->nPrecinctCount = nPrecinctsCount; + // } + + // // CodeBlockDimension + // if (oSaveNode.GetNode(_T("CodeBlockDimension"), oCurNode)) + // { + // sValue = oCurNode.GetAttribute(_T("width"), _T("64")); + // pParameters->nCodeBlockWidthInit = max(4, min(4096, _wtoi(sValue.GetBuffer()))); + + // sValue = oCurNode.GetAttribute(_T("height"), _T("64")); + // pParameters->nCodeBlockHeightInit = max(4, min(4096, _wtoi(sValue.GetBuffer()))); + // } + + // // ProgressionOrder + // if (oSaveNode.GetNode(_T("ProgressionOrder"), oCurNode)) + // { + // sValue = oCurNode.GetAttribute(_T("value"), _T("0")); + // int nProgOrder = max(0, min(4, _wtoi(sValue.GetBuffer()))); + // switch (nProgOrder) + // { + // case 0: pParameters->eProgOrder = poLRCP; break; + // case 1: pParameters->eProgOrder = poRLCP; break; + // case 2: pParameters->eProgOrder = poRPCL; break; + // case 3: pParameters->eProgOrder = poPCRL; break; + // case 4: pParameters->eProgOrder = poCPRL; break; + // } + // } + + // // Subsampling + // if (oSaveNode.GetNode(_T("Subsampling"), oCurNode)) + // { + // sValue = oCurNode.GetAttribute(_T("dx"), _T("1")); + // pParameters->nSubSamplingDx = max(1, min(J2K_MAXSSFTR, _wtoi(sValue.GetBuffer()))); + + // sValue = oCurNode.GetAttribute(_T("dy"), _T("1")); + // pParameters->nSubSamplingDy = max(1, min(J2K_MAXSSFTR, _wtoi(sValue.GetBuffer()))); + // } + + // // SOPmarker + // if (oSaveNode.GetNode(_T("SOPmarker"), oCurNode)) + // { + // // Пока отключим, потом надо будет добавить - для этого нужно выделять память для стрктуры ImageInfo + // //pParameters->nCodingStyle |= 0x02; + // } + + // // EPHmarker + // if (oSaveNode.GetNode(_T("EPHmarker"), oCurNode)) + // { + // pParameters->nCodingStyle |= 0x04; + // } + + // // ROI + // if (oSaveNode.GetNode(_T("ROI"), oCurNode)) + // { + // sValue = oCurNode.GetAttribute(_T("componentindex"), _T("-1")); + // pParameters->nROIComponentIndex = max(-1, _wtoi(sValue.GetBuffer())); + + // sValue = oCurNode.GetAttribute(_T("shift"), _T("0")); + // pParameters->nROIShift = max(0, min(37, _wtoi(sValue.GetBuffer()))); + // } + + // // Comment + // if (oSaveNode.GetNode(_T("Comment"), oCurNode)) + // { + // sValue = oCurNode.GetAttribute(_T("value")); + // // TO DO: Неправильное копирование строки + // USES_CONVERSION; + // pParameters->sComment = W2A(sValue.GetBuffer()); + // } + + // // Compression + // if (oSaveNode.GetNode(_T("Compression"), oCurNode)) + // { + // sValue = oCurNode.GetAttribute(_T("lossless"), _T("1")); + // pParameters->nTransformId = _wtoi(sValue.GetBuffer()) ? 0 : 1; + // } + + // // Rate-Disto + // if (oSaveNode.GetNode(_T("Rate-Disto"), oCurNode)) + // { + // sValue = oCurNode.GetText(); + + // wchar_t *wsTemp = sValue.GetBuffer(); + + // while (swscanf(wsTemp, _T("%f"), &pParameters->afRates[pParameters->nLayersCount]) == 1) + // { + // pParameters->nLayersCount++; + // while (*wsTemp && *wsTemp != _T(',')) + // { + // wsTemp++; + // } + // if (!*wsTemp) + // break; + // wsTemp++; + // } + // pParameters->nDistoAlloc = 1; + // } + + // // Fixed-Quality + // if (oSaveNode.GetNode(_T("Fixed-Quality"), oCurNode)) + // { + // sValue = oCurNode.GetText(); + + // wchar_t *wsTemp = sValue.GetBuffer(); + + // while (swscanf(wsTemp, _T("%f"), &pParameters->afDistoratio[pParameters->nLayersCount]) == 1) + // { + // pParameters->nLayersCount++; + // while (*wsTemp && *wsTemp != ',') + // { + // wsTemp++; + // } + // if (!*wsTemp) + // break; + // wsTemp++; + // } + // pParameters->nFixedQuality = 1; + // } + + // // Fixed-Layer + // if (oSaveNode.GetNode(_T("Fixed-Layer"), oCurNode)) + // { + // sValue = oCurNode.GetAttribute(_T("layerscount"), _T("1")); + // int nLayersCount = max(1, _wtoi(sValue.GetBuffer())); + // pParameters->nLayersCount = nLayersCount; + + // int nResolutionsCount = pParameters->nResolutionsCount; + // int nMatrixWidth = nResolutionsCount * 3; + // pParameters->pMatrix = (int*)Malloc(0, nLayersCount * nMatrixWidth * sizeof(int)); + + // sValue = oCurNode.GetText(); + // wchar_t *wsTemp = sValue.GetBuffer(); + + // for (int nLayerIndex = 0; nLayerIndex < nLayersCount; nLayerIndex++) + // { + // int *pRow = &pParameters->pMatrix[nLayerIndex * nMatrixWidth]; + // int *pCol = pRow; + + // pParameters->afRates[nLayerIndex] = 1; + + // swscanf(wsTemp, _T("%d,"), &pCol[0]); + // wsTemp += 2; + + // if (pCol[0] > 9) + // wsTemp++; + + // pCol[1] = 0; + // pCol[2] = 0; + + // for (int nResolutionIndex = 1; nResolutionIndex < nResolutionsCount; nResolutionIndex++) + // { + // pCol += 3; + // swscanf(wsTemp, _T("%d,%d,%d"), &pCol[0], &pCol[1], &pCol[2]); + // wsTemp += 6; + // if (pCol[0] > 9) + // wsTemp++; + // if (pCol[1] > 9) + // wsTemp++; + // if (pCol[2] > 9) + // wsTemp++; + // } + // if (nLayerIndex < nLayersCount - 1) + // wsTemp++; + // } + + // pParameters->nFixedAlloc = 1; + + // } + // } + + // } + //} + + + // Проверим кооректность введенных параметров + + // Параметры nDistoAlloc, nFixedQuality, nFixedAlloc нельзя использовать вместе + if ((pParameters->nDistoAlloc || pParameters->nFixedAlloc || pParameters->nFixedQuality) && (!(pParameters->nDistoAlloc ^ pParameters->nFixedAlloc ^ pParameters->nFixedQuality))) + return -1; + + // Если параметры не заданы, тогда по умолчанию ставим компрессию без потерь + if (0 == pParameters->nLayersCount) + { + pParameters->afRates[0] = 0; + pParameters->nLayersCount = 1; + pParameters->nDistoAlloc = 1; + } + if (pParameters->nXTOsiz > pParameters->nImageOffsetX0 || pParameters->nYTOsiz > pParameters->nImageOffsetY0) + return -1; + + for (int nIndex = 0; nIndex < pParameters->nPOCsCount; nIndex++) + { + if (-1 == pParameters->aoPOC[nIndex].ePpoc) + { + // TO DO: Выдать ошибку, что порядок не задан + } + } + + return nFormat; + } +} diff --git a/DesktopEditor/raster/Jp2/J2kFile.h b/DesktopEditor/raster/Jp2/J2kFile.h index bbb08da16e..ab0b42aa2f 100644 --- a/DesktopEditor/raster/Jp2/J2kFile.h +++ b/DesktopEditor/raster/Jp2/J2kFile.h @@ -1,15 +1,11 @@ // J2kFile.h : Declaration of the CJ2kFile #pragma once - -#include "Types.h" #include "../BgraFrame.h" -#include namespace Jpeg2000 { - - class CJ2kFile + class GRAPHICS_DECL CJ2kFile { public: bool Open(CBgraFrame* pFrame, const std::wstring& wsSrcPath, const std::wstring& wsXmlOptions); @@ -17,335 +13,7 @@ namespace Jpeg2000 bool Open(BYTE** ppData, int& nComponentsCount, int& nWidth, int& nHeight, const std::wstring& wsSrcPath, const std::wstring& wsXmlOptions); private: - void ApplyDecoderOptions(DecoderParams *pParameters, const std::wstring& sXml) - { - memset(pParameters, 0, sizeof(DecoderParams)); - pParameters->eLimitDecoding = declimNoLimitation; - pParameters->nReduce = 0; - pParameters->nLayer = 0; - - // TODO: Сделать чтение параметров декодирования - //if (sXml.GetLength() > 0) - //{ - // XmlUtils::CXmlNode oMainNode; - // oMainNode.FromXmlString(sXml); - - // if (-1 != oMainNode.GetName().Find(_T("Jpeg2000-Options"))) - // { - // XmlUtils::CXmlNode oOpenNode; - // if (oMainNode.GetNode(_T("OpenOptions"), oOpenNode)) - // { - // XmlUtils::CXmlNode oCurNode; - // CString sValue; - - // // ReduceFactor - // if (oOpenNode.GetNode(_T("ConvertToRGBA"), oCurNode)) - // { - // sValue = oCurNode.GetAttribute(_T("value"), _T("0")); - // pParameters->bConvertToRGBA = (_wtoi(sValue.GetBuffer()) ? true : false); - // } - - // // ReduceFactor - // if (oOpenNode.GetNode(_T("ReduceFactor"), oCurNode)) - // { - // sValue = oCurNode.GetAttribute(_T("value"), _T("0")); - // pParameters->nReduce = _wtoi(sValue.GetBuffer()); - // } - - // // LayersCount - // if (oOpenNode.GetNode(_T("LayersCount"), oCurNode)) - // { - // sValue = oCurNode.GetAttribute(_T("value"), _T("0")); - // pParameters->nLayer = _wtoi(sValue.GetBuffer()); - // } - // } - // } - //} - } - long ApplyEncoderOptions(EncoderParams *pParameters, const std::wstring& sXml) - { - int nFormat = 0; // J2k - // Сначала выставляем стандартные значения параметров - memset(pParameters, 0, sizeof(EncoderParams)); - pParameters->nComponentsCount = 3; - pParameters->nResolutionsCount = 6; - pParameters->nCodeBlockHeightInit = 64; - pParameters->nCodeBlockWidthInit = 64; - pParameters->eProgOrder = poLRCP; - pParameters->nROIComponentIndex = -1; // Нет ROI - pParameters->nSubSamplingDx = 1; - pParameters->nSubSamplingDy = 1; - pParameters->bTileSizeOn = false; - pParameters->sComment = (char*)"Manufactured by Online Media Technologies Ltd."; - - // TODO: Сделать чтение параметров кодирования - //if (sXml.GetLength() > 0) - //{ - // XmlUtils::CXmlNode oMainNode; - // oMainNode.FromXmlString(sXml); - - // if (-1 != oMainNode.GetName().Find(_T("Jpeg2000-Options"))) - // { - // XmlUtils::CXmlNode oSaveNode; - // if (oMainNode.GetNode(_T("SaveOptions"), oSaveNode)) - // { - // XmlUtils::CXmlNode oCurNode; - // CString sValue; - - // // ComponentsCount - // if (oSaveNode.GetNode(_T("ComponentsCount"), oCurNode)) - // { - // pParameters->nComponentsCount = XmlUtils::GetInteger(oCurNode.GetAttribute(_T("value"), _T("3"))); - // } - - - // // Format - // if (oSaveNode.GetNode(_T("Format"), oCurNode)) - // { - // sValue = oCurNode.GetAttribute(_T("value"), _T("0")); - // nFormat = _wtoi(sValue.GetBuffer()); - // } - - // // Tile - // if (oSaveNode.GetNode(_T("Tile"), oCurNode)) - // { - // sValue = oCurNode.GetAttribute(_T("width"), _T("32")); - // pParameters->nXTsiz = max(32, _wtoi(sValue.GetBuffer())); - // sValue = oCurNode.GetAttribute(_T("height"), _T("32")); - // pParameters->nYTsiz = max(32, _wtoi(sValue.GetBuffer())); - - // pParameters->bTileSizeOn = true; - - // sValue = oCurNode.GetAttribute(_T("offsetx"), _T("0")); - // pParameters->nXTOsiz = _wtoi(sValue.GetBuffer()); - // sValue = oCurNode.GetAttribute(_T("offsety"), _T("0")); - // pParameters->nYTOsiz = _wtoi(sValue.GetBuffer()); - // } - - // // Resolution - // if (oSaveNode.GetNode(_T("Resolution"), oCurNode)) - // { - // sValue = oCurNode.GetAttribute(_T("levelscount"), _T("6")); - // pParameters->nResolutionsCount = max(1, min(J2K_MAXRLVLS, _wtoi(sValue.GetBuffer()))); - // } - - // // PrecinctDimension - // if (oSaveNode.GetNode(_T("PrecinctDimension"), oCurNode)) - // { - // sValue = oCurNode.GetText(); - // wchar_t *wsTemp = sValue.GetBuffer(); - - // char nSeparateChar = 0; - // int nPrecinctsCount = 0; - // do - // { - // nSeparateChar = 0; - // swscanf(wsTemp, _T("[%d,%d]%c"), &pParameters->anPrecinctWidthInit[nPrecinctsCount], &pParameters->anPrecinctHeightInit[nPrecinctsCount], &nSeparateChar); - // pParameters->nCodingStyle |= 0x01; - // nPrecinctsCount++; - // if (J2K_MAXRLVLS == nPrecinctsCount) - // break; - // wsTemp = wcspbrk(wsTemp, _T("]")) + 2; - // } while (',' == nSeparateChar); - // pParameters->nPrecinctCount = nPrecinctsCount; - // } - - // // CodeBlockDimension - // if (oSaveNode.GetNode(_T("CodeBlockDimension"), oCurNode)) - // { - // sValue = oCurNode.GetAttribute(_T("width"), _T("64")); - // pParameters->nCodeBlockWidthInit = max(4, min(4096, _wtoi(sValue.GetBuffer()))); - - // sValue = oCurNode.GetAttribute(_T("height"), _T("64")); - // pParameters->nCodeBlockHeightInit = max(4, min(4096, _wtoi(sValue.GetBuffer()))); - // } - - // // ProgressionOrder - // if (oSaveNode.GetNode(_T("ProgressionOrder"), oCurNode)) - // { - // sValue = oCurNode.GetAttribute(_T("value"), _T("0")); - // int nProgOrder = max(0, min(4, _wtoi(sValue.GetBuffer()))); - // switch (nProgOrder) - // { - // case 0: pParameters->eProgOrder = poLRCP; break; - // case 1: pParameters->eProgOrder = poRLCP; break; - // case 2: pParameters->eProgOrder = poRPCL; break; - // case 3: pParameters->eProgOrder = poPCRL; break; - // case 4: pParameters->eProgOrder = poCPRL; break; - // } - // } - - // // Subsampling - // if (oSaveNode.GetNode(_T("Subsampling"), oCurNode)) - // { - // sValue = oCurNode.GetAttribute(_T("dx"), _T("1")); - // pParameters->nSubSamplingDx = max(1, min(J2K_MAXSSFTR, _wtoi(sValue.GetBuffer()))); - - // sValue = oCurNode.GetAttribute(_T("dy"), _T("1")); - // pParameters->nSubSamplingDy = max(1, min(J2K_MAXSSFTR, _wtoi(sValue.GetBuffer()))); - // } - - // // SOPmarker - // if (oSaveNode.GetNode(_T("SOPmarker"), oCurNode)) - // { - // // Пока отключим, потом надо будет добавить - для этого нужно выделять память для стрктуры ImageInfo - // //pParameters->nCodingStyle |= 0x02; - // } - - // // EPHmarker - // if (oSaveNode.GetNode(_T("EPHmarker"), oCurNode)) - // { - // pParameters->nCodingStyle |= 0x04; - // } - - // // ROI - // if (oSaveNode.GetNode(_T("ROI"), oCurNode)) - // { - // sValue = oCurNode.GetAttribute(_T("componentindex"), _T("-1")); - // pParameters->nROIComponentIndex = max(-1, _wtoi(sValue.GetBuffer())); - - // sValue = oCurNode.GetAttribute(_T("shift"), _T("0")); - // pParameters->nROIShift = max(0, min(37, _wtoi(sValue.GetBuffer()))); - // } - - // // Comment - // if (oSaveNode.GetNode(_T("Comment"), oCurNode)) - // { - // sValue = oCurNode.GetAttribute(_T("value")); - // // TO DO: Неправильное копирование строки - // USES_CONVERSION; - // pParameters->sComment = W2A(sValue.GetBuffer()); - // } - - // // Compression - // if (oSaveNode.GetNode(_T("Compression"), oCurNode)) - // { - // sValue = oCurNode.GetAttribute(_T("lossless"), _T("1")); - // pParameters->nTransformId = _wtoi(sValue.GetBuffer()) ? 0 : 1; - // } - - // // Rate-Disto - // if (oSaveNode.GetNode(_T("Rate-Disto"), oCurNode)) - // { - // sValue = oCurNode.GetText(); - - // wchar_t *wsTemp = sValue.GetBuffer(); - - // while (swscanf(wsTemp, _T("%f"), &pParameters->afRates[pParameters->nLayersCount]) == 1) - // { - // pParameters->nLayersCount++; - // while (*wsTemp && *wsTemp != _T(',')) - // { - // wsTemp++; - // } - // if (!*wsTemp) - // break; - // wsTemp++; - // } - // pParameters->nDistoAlloc = 1; - // } - - // // Fixed-Quality - // if (oSaveNode.GetNode(_T("Fixed-Quality"), oCurNode)) - // { - // sValue = oCurNode.GetText(); - - // wchar_t *wsTemp = sValue.GetBuffer(); - - // while (swscanf(wsTemp, _T("%f"), &pParameters->afDistoratio[pParameters->nLayersCount]) == 1) - // { - // pParameters->nLayersCount++; - // while (*wsTemp && *wsTemp != ',') - // { - // wsTemp++; - // } - // if (!*wsTemp) - // break; - // wsTemp++; - // } - // pParameters->nFixedQuality = 1; - // } - - // // Fixed-Layer - // if (oSaveNode.GetNode(_T("Fixed-Layer"), oCurNode)) - // { - // sValue = oCurNode.GetAttribute(_T("layerscount"), _T("1")); - // int nLayersCount = max(1, _wtoi(sValue.GetBuffer())); - // pParameters->nLayersCount = nLayersCount; - - // int nResolutionsCount = pParameters->nResolutionsCount; - // int nMatrixWidth = nResolutionsCount * 3; - // pParameters->pMatrix = (int*)Malloc(0, nLayersCount * nMatrixWidth * sizeof(int)); - - // sValue = oCurNode.GetText(); - // wchar_t *wsTemp = sValue.GetBuffer(); - - // for (int nLayerIndex = 0; nLayerIndex < nLayersCount; nLayerIndex++) - // { - // int *pRow = &pParameters->pMatrix[nLayerIndex * nMatrixWidth]; - // int *pCol = pRow; - - // pParameters->afRates[nLayerIndex] = 1; - - // swscanf(wsTemp, _T("%d,"), &pCol[0]); - // wsTemp += 2; - - // if (pCol[0] > 9) - // wsTemp++; - - // pCol[1] = 0; - // pCol[2] = 0; - - // for (int nResolutionIndex = 1; nResolutionIndex < nResolutionsCount; nResolutionIndex++) - // { - // pCol += 3; - // swscanf(wsTemp, _T("%d,%d,%d"), &pCol[0], &pCol[1], &pCol[2]); - // wsTemp += 6; - // if (pCol[0] > 9) - // wsTemp++; - // if (pCol[1] > 9) - // wsTemp++; - // if (pCol[2] > 9) - // wsTemp++; - // } - // if (nLayerIndex < nLayersCount - 1) - // wsTemp++; - // } - - // pParameters->nFixedAlloc = 1; - - // } - // } - - // } - //} - - - // Проверим кооректность введенных параметров - - // Параметры nDistoAlloc, nFixedQuality, nFixedAlloc нельзя использовать вместе - if ((pParameters->nDistoAlloc || pParameters->nFixedAlloc || pParameters->nFixedQuality) && (!(pParameters->nDistoAlloc ^ pParameters->nFixedAlloc ^ pParameters->nFixedQuality))) - return -1; - - // Если параметры не заданы, тогда по умолчанию ставим компрессию без потерь - if (0 == pParameters->nLayersCount) - { - pParameters->afRates[0] = 0; - pParameters->nLayersCount = 1; - pParameters->nDistoAlloc = 1; - } - if (pParameters->nXTOsiz > pParameters->nImageOffsetX0 || pParameters->nYTOsiz > pParameters->nImageOffsetY0) - return -1; - - for (int nIndex = 0; nIndex < pParameters->nPOCsCount; nIndex++) - { - if (-1 == pParameters->aoPOC[nIndex].ePpoc) - { - // TO DO: Выдать ошибку, что порядок не задан - } - } - - return nFormat; - } + void ApplyDecoderOptions(void *pParameters, const std::wstring& sXml); + long ApplyEncoderOptions(void *pParameters, const std::wstring& sXml); }; } diff --git a/DjVuFile/DjVuFile.pro b/DjVuFile/DjVuFile.pro index 36264c9895..792c43cc32 100644 --- a/DjVuFile/DjVuFile.pro +++ b/DjVuFile/DjVuFile.pro @@ -28,8 +28,6 @@ DEFINES -= \ UNICODE \ _UNICODE -DEFINES += NOMINMAX - core_linux { DEFINES += \ HAVE_UNISTD_H \ diff --git a/OfficeUtils/src/OfficeUtils.cpp b/OfficeUtils/src/OfficeUtils.cpp index d04d6e87d5..795776d72f 100644 --- a/OfficeUtils/src/OfficeUtils.cpp +++ b/OfficeUtils/src/OfficeUtils.cpp @@ -227,3 +227,75 @@ void CDeflate::End() { deflateEnd(&m_internal->m_stream); } + +/////////////////////////////////////////// +class CInflate_private +{ +public: + z_stream m_stream; + +public: + CInflate_private() + { + memset(&m_stream, 0x00, sizeof(z_stream)); + } +}; + +CInflate::CInflate() +{ + m_internal = new CInflate_private(); +} +CInflate::~CInflate() +{ + delete m_internal; +} + +void CInflate::SetIn(BYTE* next_in, UINT avail_in, ULONG total_in) +{ + m_internal->m_stream.next_in = next_in; + m_internal->m_stream.avail_in = avail_in; + + if (-1 != total_in) + m_internal->m_stream.total_in = total_in; +} + +void CInflate::SetOut(BYTE* next_out, UINT avail_out, ULONG total_out) +{ + m_internal->m_stream.next_out = next_out; + m_internal->m_stream.avail_out = avail_out; + + if (-1 != total_out) + m_internal->m_stream.total_out = total_out; +} + +UINT CInflate::GetAvailIn() +{ + return m_internal->m_stream.avail_in; +} + +UINT CInflate::GetAvailOut() +{ + return m_internal->m_stream.avail_out; +} + +void CInflate::Init() +{ + inflateInit(&m_internal->m_stream); +} + +int CInflate::Process(int flush) +{ + return inflate(&m_internal->m_stream, flush); +} + +void CInflate::End() +{ + inflateEnd(&m_internal->m_stream); +} + +void CInflate::ClearFuncs() +{ + m_internal->m_stream.zalloc = Z_NULL; + m_internal->m_stream.zfree = Z_NULL; + m_internal->m_stream.opaque = Z_NULL; +} diff --git a/OfficeUtils/src/OfficeUtils.h b/OfficeUtils/src/OfficeUtils.h index 025959c8b4..e63c96e04a 100644 --- a/OfficeUtils/src/OfficeUtils.h +++ b/OfficeUtils/src/OfficeUtils.h @@ -57,16 +57,23 @@ public: }; -#define DEFLATE_OK 0 -#define DEFLATE_STREAM_END 1 - #define DEFLATE_NO_FLUSH 0 -#define DEFLATE_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */ +#define DEFLATE_PARTIAL_FLUSH 1 /* will be removed, use DEFLATE_SYNC_FLUSH instead */ #define DEFLATE_SYNC_FLUSH 2 #define DEFLATE_FULL_FLUSH 3 #define DEFLATE_FINISH 4 #define DEFLATE_BLOCK 5 +#define DEFLATE_OK 0 +#define DEFLATE_STREAM_END 1 +#define DEFLATE_NEED_DICT 2 +#define DEFLATE_ERRNO (-1) +#define DEFLATE_STREAM_ERROR (-2) +#define DEFLATE_DATA_ERROR (-3) +#define DEFLATE_MEM_ERROR (-4) +#define DEFLATE_BUF_ERROR (-5) +#define DEFLATE_VERSION_ERROR (-6) + #define DEFLATE_NO_COMPRESSION 0 #define DEFLATE_BEST_SPEED 1 #define DEFLATE_BEST_COMPRESSION 9 @@ -94,4 +101,28 @@ public: void End(); }; +class CInflate_private; +class KERNEL_DECL CInflate +{ +private: + CInflate_private* m_internal; + +public: + CInflate(); + ~CInflate(); + +public: + void SetIn(BYTE* next_in, UINT avail_in, ULONG total_in = -1); + void SetOut(BYTE* next_out, UINT avail_out, ULONG total_out = -1); + + UINT GetAvailIn(); + UINT GetAvailOut(); + + void ClearFuncs(); + + void Init(); + int Process(int flush); + void End(); +}; + #endif diff --git a/PdfReader/PdfReader.cpp b/PdfReader/PdfReader.cpp index 14ff68b26c..7fc4790769 100644 --- a/PdfReader/PdfReader.cpp +++ b/PdfReader/PdfReader.cpp @@ -29,12 +29,10 @@ * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode * */ +#include "../DesktopEditor/graphics/pro/Graphics.h" #include "PdfReader.h" #include "../Common/OfficeDefines.h" #include "../DesktopEditor/raster/BgraFrame.h" -#include "../DesktopEditor/graphics/GraphicsRenderer.h" -#include "../DesktopEditor/fontengine/ApplicationFonts.h" -#include "../DesktopEditor/fontengine/FontManager.h" #include "../DesktopEditor/graphics/IRenderer.h" #include "../DesktopEditor/common/Directory.h" @@ -45,8 +43,6 @@ #include "Src/ExtractImageOutputDev.h" #include "Src/RendererOutputDev.h" -#include - namespace PdfReader { class CPdfReader_Private @@ -56,12 +52,12 @@ namespace PdfReader GlobalParams* m_pGlobalParams; std::wstring m_wsTempFolder; std::wstring m_wsCMapFolder; - CApplicationFonts* m_pAppFonts; - CFontManager* m_pFontManager; + NSFonts::IApplicationFonts* m_pAppFonts; + NSFonts::IFontManager* m_pFontManager; CFontList* m_pFontList; }; - CPdfReader::CPdfReader(CApplicationFonts* pAppFonts) + CPdfReader::CPdfReader(NSFonts::IApplicationFonts* pAppFonts) { m_pInternal = new CPdfReader_Private(); @@ -78,7 +74,7 @@ namespace PdfReader // Создаем менеджер шрифтов с собственным кэшем m_pInternal->m_pFontManager = pAppFonts->GenerateFontManager(); - CFontsCache* pMeasurerCache = new CFontsCache(); + NSFonts::IFontsCache* pMeasurerCache = NSFonts::NSFontCache::Create(); pMeasurerCache->SetStreams(pAppFonts->GetStreams()); m_pInternal->m_pFontManager->SetOwnerCache(pMeasurerCache); pMeasurerCache->SetCacheSize(1); @@ -114,7 +110,7 @@ namespace PdfReader //------------------------------------------------------ RELEASEINTERFACE((m_pInternal->m_pFontManager)); m_pInternal->m_pFontManager = m_pInternal->m_pAppFonts->GenerateFontManager(); - CFontsCache* pMeasurerCache = new CFontsCache(); + NSFonts::IFontsCache* pMeasurerCache = NSFonts::NSFontCache::Create(); pMeasurerCache->SetStreams(m_pInternal->m_pAppFonts->GetStreams()); m_pInternal->m_pFontManager->SetOwnerCache(pMeasurerCache); pMeasurerCache->SetCacheSize(1); @@ -262,13 +258,13 @@ namespace PdfReader } void CPdfReader::ConvertToRaster(int nPageIndex, const std::wstring& wsDstPath, int nImageType, const int nRasterW, const int nRasterH) { - CFontManager *pFontManager = m_pInternal->m_pAppFonts->GenerateFontManager(); - CFontsCache* pFontCache = new CFontsCache(); + NSFonts::IFontManager *pFontManager = m_pInternal->m_pAppFonts->GenerateFontManager(); + NSFonts::IFontsCache* pFontCache = NSFonts::NSFontCache::Create(); pFontCache->SetStreams(m_pInternal->m_pAppFonts->GetStreams()); pFontManager->SetOwnerCache(pFontCache); - CGraphicsRenderer oRenderer; - oRenderer.SetFontManager(pFontManager); + NSGraphics::IGraphicsRenderer* pRenderer = NSGraphics::Create(); + pRenderer->SetFontManager(pFontManager); double dWidth, dHeight; double dDpiX, dDpiY; @@ -288,20 +284,21 @@ namespace PdfReader oFrame.put_Height(nHeight); oFrame.put_Stride(-4 * nWidth); - oRenderer.CreateFromBgraFrame(&oFrame); - oRenderer.SetSwapRGB(false); + pRenderer->CreateFromBgraFrame(&oFrame); + pRenderer->SetSwapRGB(false); dWidth *= 25.4 / dDpiX; dHeight *= 25.4 / dDpiY; - oRenderer.put_Width(dWidth); - oRenderer.put_Height(dHeight); + pRenderer->put_Width(dWidth); + pRenderer->put_Height(dHeight); bool bBreak = false; - DrawPageOnRenderer(&oRenderer, nPageIndex, &bBreak); + DrawPageOnRenderer(pRenderer, nPageIndex, &bBreak); oFrame.SaveFile(wsDstPath, nImageType); RELEASEINTERFACE(pFontManager); + RELEASEOBJECT(pRenderer); } int CPdfReader::GetImagesCount() { @@ -355,7 +352,7 @@ namespace PdfReader if (m_pInternal->m_pGlobalParams) m_pInternal->m_pGlobalParams->SetCMapFolder(m_pInternal->m_wsCMapFolder.c_str()); } - CFontManager* CPdfReader::GetFontManager() + NSFonts::IFontManager* CPdfReader::GetFontManager() { return m_pInternal->m_pFontManager; } diff --git a/PdfReader/PdfReader.h b/PdfReader/PdfReader.h index 2b22fd9d30..3e69818fe9 100644 --- a/PdfReader/PdfReader.h +++ b/PdfReader/PdfReader.h @@ -41,6 +41,7 @@ #include "Src/ErrorConstants.h" #include "../DesktopEditor/common/officedrawingfile.h" +#include "../DesktopEditor/graphics/pro/Fonts.h" namespace PdfReader { @@ -49,7 +50,7 @@ namespace PdfReader { public: - CPdfReader(CApplicationFonts* fonts); + CPdfReader(NSFonts::IApplicationFonts* fonts); virtual ~CPdfReader(); virtual bool LoadFromFile(const std::wstring& file, const std::wstring& options = L"", @@ -73,7 +74,7 @@ namespace PdfReader int GetImagesCount(); void SetCMapFolder(const wchar_t* wsCMapFolder); - CFontManager*GetFontManager(); + NSFonts::IFontManager* GetFontManager(); private: CPdfReader_Private* m_pInternal; diff --git a/PdfReader/PdfReader.pro b/PdfReader/PdfReader.pro index d3858a2579..68442a1b7e 100644 --- a/PdfReader/PdfReader.pro +++ b/PdfReader/PdfReader.pro @@ -23,8 +23,6 @@ LIBS += -L$$CORE_BUILDS_LIBRARIES_PATH -lUnicodeConverter -lkernel -lgraphics core_windows { -DEFINES -= NOMINMAX - LIBS += -lgdi32 \ -ladvapi32 \ -luser32 \ diff --git a/PdfReader/Src/GlobalParams.cpp b/PdfReader/Src/GlobalParams.cpp index cff7ba8b94..6f27f5a66e 100644 --- a/PdfReader/Src/GlobalParams.cpp +++ b/PdfReader/Src/GlobalParams.cpp @@ -233,11 +233,11 @@ namespace PdfReader else m_wsCMapDirectory = L""; } - void GlobalParams::SetFontManager(CFontManager* pFontManager) + void GlobalParams::SetFontManager(NSFonts::IFontManager* pFontManager) { m_pFontManager = pFontManager; } - CFontManager* GlobalParams::GetFontManager() const + NSFonts::IFontManager* GlobalParams::GetFontManager() const { return m_pFontManager; } diff --git a/PdfReader/Src/GlobalParams.h b/PdfReader/Src/GlobalParams.h index abe8070fb6..d9e3023b67 100644 --- a/PdfReader/Src/GlobalParams.h +++ b/PdfReader/Src/GlobalParams.h @@ -38,8 +38,7 @@ #include "CharTypes.h" #include "../../DesktopEditor/graphics/TemporaryCS.h" -#include "../../DesktopEditor/fontengine/FontManager.h" - +#include "../../DesktopEditor/graphics/pro/Fonts.h" namespace PdfReader { @@ -80,8 +79,8 @@ namespace PdfReader void SetTempFolder(const wchar_t* wsTempFolder); std::wstring FindFontFile(StringExt* seFontName, wchar_t** pwsExts); void SetCMapFolder(const wchar_t* wsDir); - void SetFontManager(CFontManager* pFontManager); - CFontManager* GetFontManager() const; + void SetFontManager(NSFonts::IFontManager* pFontManager); + NSFonts::IFontManager* GetFontManager() const; std::wstring GetBuiltinFontPath(StringExt* seFontName) const; private: @@ -96,7 +95,7 @@ namespace PdfReader std::wstring m_wsCMapDirectory; // Путь к папке с CMap файлами std::wstring m_wsTempDirectory; - CFontManager* m_pFontManager; + NSFonts::IFontManager* m_pFontManager; std::wstring m_arrBuiltinFontsPath[14]; // Пути к стандартным 14 шрифтам }; } diff --git a/PdfReader/Src/RendererOutputDev.cpp b/PdfReader/Src/RendererOutputDev.cpp index 1885843ec6..bf1023f7e4 100644 --- a/PdfReader/Src/RendererOutputDev.cpp +++ b/PdfReader/Src/RendererOutputDev.cpp @@ -42,7 +42,7 @@ #include "XmlUtils.h" #include "../../DesktopEditor/graphics/Image.h" -#include "../../DesktopEditor/fontengine/ApplicationFonts.h" +#include "../../DesktopEditor/graphics/pro/Fonts.h" #include "../../DesktopEditor/common/File.h" #include "../../DesktopEditor/common/Array.h" #include "../../DesktopEditor/graphics/BaseThread.h" @@ -305,7 +305,7 @@ namespace PdfReader //-------------------------------------------------------------------------------------- // RendererOutputDev //-------------------------------------------------------------------------------------- - RendererOutputDev::RendererOutputDev(GlobalParams *pGlobalParams, IRenderer *pRenderer, CFontManager* pFontManager, CFontList *pFontList) + RendererOutputDev::RendererOutputDev(GlobalParams *pGlobalParams, IRenderer *pRenderer, NSFonts::IFontManager* pFontManager, CFontList *pFontList) { m_pFontManager = pFontManager; m_pGlobalParams = pGlobalParams; @@ -910,7 +910,7 @@ namespace PdfReader // TODO: Сначала тут мы должны проверить, если ищется один из 14 стандартных шрифтов, // тогда мы должны вернуть путь к стандартному шрифту. - CFontInfo* pFontInfo = NULL; + NSFonts::CFontInfo* pFontInfo = NULL; if (m_pFontManager) { Ref *pRef = pFont->GetID(); @@ -919,7 +919,7 @@ namespace PdfReader oRefObject.Fetch(m_pXref, &oFontObject); oRefObject.Free(); - CFontSelectFormat oFontSelect; + NSFonts::CFontSelectFormat oFontSelect; std::wstring wsFontBaseName = pFont->GetBaseName()->GetWString(); if (oFontObject.IsDict()) { diff --git a/PdfReader/Src/RendererOutputDev.h b/PdfReader/Src/RendererOutputDev.h index 8a27a655a1..4962ebb182 100644 --- a/PdfReader/Src/RendererOutputDev.h +++ b/PdfReader/Src/RendererOutputDev.h @@ -33,7 +33,7 @@ #define _PDF_READER_RENDERER_OUTPUTDEV_H #include "../../DesktopEditor/graphics/IRenderer.h" -#include "../../DesktopEditor/fontengine/FontManager.h" +#include "../../DesktopEditor/graphics/pro/Fonts.h" #include "../../DesktopEditor/graphics/TemporaryCS.h" #include "OutputDevice.h" @@ -118,7 +118,7 @@ namespace PdfReader { public: - RendererOutputDev(GlobalParams *pGlobalParams, IRenderer *pRenderer, CFontManager* pFontManager, CFontList *pFontList = NULL); + RendererOutputDev(GlobalParams *pGlobalParams, IRenderer *pRenderer, NSFonts::IFontManager* pFontManager, CFontList *pFontList = NULL); virtual ~RendererOutputDev(); virtual bool UpSideDown() { @@ -279,7 +279,7 @@ namespace PdfReader IRenderer* m_pRenderer; long m_lRendererType; double m_arrMatrix[6]; - CFontManager* m_pFontManager; + NSFonts::IFontManager* m_pFontManager; GrTextClip *m_pBufferTextClip; diff --git a/PdfReader/Src/Stream.cpp b/PdfReader/Src/Stream.cpp index 78db4301db..a5d96110b3 100644 --- a/PdfReader/Src/Stream.cpp +++ b/PdfReader/Src/Stream.cpp @@ -3774,11 +3774,9 @@ namespace PdfReader memset(m_arrInBuffer, 0, flateZlibWindow); memset(m_arrBuffer, 0, flateZlibWindow); - m_oZStream.zalloc = Z_NULL; - m_oZStream.zfree = Z_NULL; - m_oZStream.opaque = Z_NULL; + m_oZStream.ClearFuncs(); - inflateInit(&m_oZStream); + m_oZStream.Init(); } FlateZlibStream::~FlateZlibStream() @@ -3789,7 +3787,7 @@ namespace PdfReader } delete m_pStream; - inflateEnd(&m_oZStream); + m_oZStream.End(); } void FlateZlibStream::Reset() @@ -3800,14 +3798,9 @@ namespace PdfReader m_bEndOfBlock = true; m_bEOF = true; - - inflateEnd(&m_oZStream); - - m_oZStream.zalloc = Z_NULL; - m_oZStream.zfree = Z_NULL; - m_oZStream.opaque = Z_NULL; - - inflateInit(&m_oZStream); + m_oZStream.End(); + m_oZStream.ClearFuncs(); + m_oZStream.Init(); m_pStream->Reset(); @@ -3911,27 +3904,25 @@ namespace PdfReader m_arrInBuffer[unIndex] = nChar; } - m_oZStream.avail_in = unInSize; - m_oZStream.next_in = (Bytef *)m_arrInBuffer; + m_oZStream.SetIn(m_arrInBuffer, unInSize); m_bEndOfBlock = false; } - m_oZStream.avail_out = flateZlibWindow; - m_oZStream.next_out = (Bytef *)m_arrBuffer; + m_oZStream.SetOut(m_arrBuffer, flateZlibWindow); - int nRet = inflate(&m_oZStream, Z_NO_FLUSH); + int nRet = m_oZStream.Process(DEFLATE_NO_FLUSH); - if (nRet == Z_DATA_ERROR || nRet == Z_MEM_ERROR) + if (nRet == DEFLATE_DATA_ERROR || nRet == DEFLATE_MEM_ERROR) { m_nRemain = 0; m_bEOF = m_bEndOfBlock = true; return; } - m_nRemain = flateZlibWindow - m_oZStream.avail_out; + m_nRemain = flateZlibWindow - m_oZStream.GetAvailOut(); - if (m_oZStream.avail_out != 0) + if (m_oZStream.GetAvailOut() != 0) m_bEndOfBlock = true; return; diff --git a/PdfReader/Src/Stream.h b/PdfReader/Src/Stream.h index c32129f1b4..0cf1f28080 100644 --- a/PdfReader/Src/Stream.h +++ b/PdfReader/Src/Stream.h @@ -34,10 +34,7 @@ #include #include "Object.h" - -#include "zlib.h" - -//#pragma comment(lib, "zlib.lib") +#include "../../OfficeUtils/src/OfficeUtils.h" namespace PdfReader { @@ -462,7 +459,7 @@ namespace PdfReader virtual void Reset() { } - virtual void Close(){}; + virtual void Close(){} virtual int GetChar(); virtual int LookChar(); virtual int GetPos() @@ -847,7 +844,7 @@ namespace PdfReader private: - z_stream m_oZStream; // Zlib поток + CInflate m_oZStream; // Zlib поток StreamPredictor *m_pPredictor; // Predictor unsigned int m_nInSize; // Размер входного буффера unsigned char m_arrInBuffer[flateZlibWindow]; // Входной буффер