Refactoring

This commit is contained in:
Svetlana Kulikova
2025-06-19 16:18:03 +03:00
parent d1a64d29c0
commit 426cd08d57
3 changed files with 68 additions and 77 deletions

View File

@ -1294,7 +1294,7 @@ namespace PdfWriter
{
BYTE charsetFormat;
charSet->mType = eCharSetCustom;
mPrimitivesReader->Seek(charsetPosition, SeekSet);
mPrimitivesReader->Seek((int)charsetPosition, SeekSet);
charsetFormat = mPrimitivesReader->ReadUChar();
if (0 == charsetFormat)
@ -2101,7 +2101,7 @@ namespace PdfWriter
return false;
mPrimitivesReader->Seek(mHeaderOffset, SeekSet);
unsigned int sfntVersion = mPrimitivesReader->ReadUInt();
mPrimitivesReader->ReadUInt(); // sfntVersion
mTablesCount = mPrimitivesReader->ReadUShort();
// skip the next 6
mPrimitivesReader->Seek(6, SeekCur);
@ -2131,7 +2131,7 @@ namespace PdfWriter
{
// mgubi: a TrueType composite font, just get to the right face table
// for the format see http://www.microsoft.com/typography/otspec/otff.htm
unsigned int ttcVersion = mPrimitivesReader->ReadUInt();
mPrimitivesReader->ReadUInt(); // ttcVersion
unsigned int numFonts = mPrimitivesReader->ReadUInt();
if (mFaceIndex >= numFonts)
@ -2166,12 +2166,13 @@ namespace PdfWriter
// see: https://developer.apple.com/legacy/mac/library/documentation/mac/pdf/MoreMacintoshToolbox.pdf
unsigned int rdata_pos, map_pos, rdata_len, map_offset;
(void) rdata_len;
// verify that the header is composed as expected
BYTE head[16], head2[16];
mPrimitivesReader->Seek(mHeaderOffset, SeekSet);
for (unsigned short i = 0; i < 16; i++)
for (unsigned short i = 0; i < 16; ++i)
head[i] = mPrimitivesReader->ReadUChar();
if (mPrimitivesReader->IsEof())
@ -2183,7 +2184,7 @@ namespace PdfWriter
mPrimitivesReader->Seek(map_pos, SeekSet);
for (unsigned short i = 0; i < 16; i++)
for (unsigned short i = 0; i < 16; ++i)
head2[i] = mPrimitivesReader->ReadUChar();
if (mPrimitivesReader->IsEof())
return false;
@ -2236,18 +2237,18 @@ namespace PdfWriter
for (int j = 0; j < subcnt + 1 && !mPrimitivesReader->IsEof(); ++j )
{
unsigned short res_id, res_name;
unsigned int temp, mbz, res_offset;
unsigned short res_id;
unsigned int temp, res_offset;
res_id = mPrimitivesReader->ReadUShort();
if (mPrimitivesReader->IsEof())
break;
res_name = mPrimitivesReader->ReadUShort();
mPrimitivesReader->ReadUShort(); // res_name
if (mPrimitivesReader->IsEof())
break;
temp = mPrimitivesReader->ReadUInt();
if (mPrimitivesReader->IsEof())
break;
mbz = mPrimitivesReader->ReadUInt();
mPrimitivesReader->ReadUInt(); // mbz
if (mPrimitivesReader->IsEof())
break;
res_offset = temp & 0xFFFFFFL;
@ -3159,7 +3160,6 @@ namespace PdfWriter
delete charString;
if (!status)
return NULL;
else
return inProgramCounter;
}
return NULL;
@ -4362,12 +4362,12 @@ namespace PdfWriter
std::string mOptionalEmbeddedPostscript;
unsigned short mSubsetFontGlyphsCount;
long long mCharsetPlaceHolderPosition;
long long mEncodingPlaceHolderPosition;
long long mCharstringsPlaceHolderPosition;
long long mPrivatePlaceHolderPosition;
long long mFDArrayPlaceHolderPosition;
long long mFDSelectPlaceHolderPosition;
int mCharsetPlaceHolderPosition;
int mEncodingPlaceHolderPosition;
int mCharstringsPlaceHolderPosition;
int mPrivatePlaceHolderPosition;
int mFDArrayPlaceHolderPosition;
int mFDSelectPlaceHolderPosition;
long long mEncodingPosition;
long long mCharsetPosition;
@ -4396,7 +4396,7 @@ namespace PdfWriter
bool WriteFDSelect(const std::vector<unsigned int>& inSubsetGlyphIDs, const FontDictInfoToByteMap& inNewFontDictsIndexes);
bool WriteCharStrings(const std::vector<unsigned int>& inSubsetGlyphIDs);
bool WritePrivateDictionary();
bool WritePrivateDictionaryBody(const PrivateDictInfo& inPrivateDictionary, long long& outWriteSize, long long& outWritePosition);
void WritePrivateDictionaryBody(const PrivateDictInfo& inPrivateDictionary, long long& outWriteSize, long long& outWritePosition);
bool WriteFDArray(const std::vector<unsigned int>& inSubsetGlyphIDs, const FontDictInfoToByteMap& inNewFontDictsIndexes);
bool UpdateIndexesAtTopDict();
};
@ -4411,7 +4411,6 @@ namespace PdfWriter
bool CCFFWriter::CreateCFFSubset(BYTE* pFile, unsigned int nLen, unsigned short unFontIndex, const std::string& inSubsetFontName, CStream* pOutputStream, unsigned short* pCodeToGID, unsigned int unCodesCount)
{
mFile = pFile;
bool outNotEmbedded = true;
bool status = mOpenTypeInput.ReadOpenTypeFile(pFile, nLen, unFontIndex);
if (!status)
@ -4422,12 +4421,7 @@ namespace PdfWriter
// see if font may be embedded
if (mOpenTypeInput.mOS2Exists && !FSType::CanEmbed(mOpenTypeInput.mOS2.fsType))
{
outNotEmbedded = true;
return true;
}
else
outNotEmbedded = false;
std::vector<unsigned int> subsetGlyphIDs;
for (unsigned long i = 0; i < unCodesCount; ++i)
@ -4582,7 +4576,7 @@ namespace PdfWriter
topDictSegment->Seek(0, SeekSet);
long long topDictDataOffset = mFontFileStream->Tell();
int topDictDataOffset = mFontFileStream->Tell();
// Write data
mFontFileStream->WriteStream(topDictSegment, 0, NULL);
@ -4940,7 +4934,7 @@ namespace PdfWriter
{
return WritePrivateDictionaryBody(mOpenTypeInput.mCFF.mPrivateDicts[0], mPrivateSize, mPrivatePosition);
}
bool CCFFWriter::WritePrivateDictionaryBody(const PrivateDictInfo& inPrivateDictionary, long long& outWriteSize, long long& outWritePosition)
void CCFFWriter::WritePrivateDictionaryBody(const PrivateDictInfo& inPrivateDictionary, long long& outWriteSize, long long& outWritePosition)
{
// just copy the private dict, without the subrs reference
if (inPrivateDictionary.mPrivateDictStart != 0)
@ -4953,13 +4947,12 @@ namespace PdfWriter
mPrimitivesWriter->WriteDictItems(it->first, it->second);
outWriteSize = mFontFileStream->Tell() - outWritePosition;
return true;
return;
}
outWritePosition = 0;
outWriteSize = 0;
return true;
}
bool CCFFWriter::WriteFDArray(const std::vector<unsigned int>& inSubsetGlyphIDs, const FontDictInfoToByteMap& inNewFontDictsIndexes)
bool CCFFWriter::WriteFDArray(const std::vector<unsigned int>&, const FontDictInfoToByteMap& inNewFontDictsIndexes)
{
// loop the glyphs IDs, for each get their respective dictionary. put them in a set.
// now itereate them, and write each private dictionary [no need for index]. save the private dictionary position.
@ -4974,21 +4967,19 @@ namespace PdfWriter
{
// if no valid font infos, write an empty index and finish
mFDArrayPosition = mFontFileStream->Tell();
status = mPrimitivesWriter->WriteCard16(0);
return status;
mPrimitivesWriter->WriteCard16(0);
return true;
}
// loop the font infos, and write the private dictionaries
long long privatePosition, privateSize;
FontDictInfoToByteMap::const_iterator itFontInfos = inNewFontDictsIndexes.begin();
for (; itFontInfos != inNewFontDictsIndexes.end() && status; ++itFontInfos)
for (; itFontInfos != inNewFontDictsIndexes.end(); ++itFontInfos)
{
status = WritePrivateDictionaryBody(itFontInfos->first->mPrivateDict, privateSize, privatePosition);
WritePrivateDictionaryBody(itFontInfos->first->mPrivateDict, privateSize, privatePosition);
privateDictionaries.insert(
FontDictInfoToLongFilePositionTypePairMap::value_type(itFontInfos->first, LongFilePositionTypePair(privateSize, privatePosition)));
}
if (!status)
return false;
// write FDArray segment
offsets = new unsigned long[inNewFontDictsIndexes.size() + 1];
@ -5073,7 +5064,7 @@ namespace PdfWriter
//----------------------------------------------------------------------------------------
// CFontFileTrueType
//----------------------------------------------------------------------------------------
void CFontFileTrueType::WriteCIDFontType0C(CStream* pOutputStream, unsigned short* pCodeToGID, unsigned int unCodesCount, unsigned char* pUseGlyfs, long lGlyfsCount)
void CFontFileTrueType::WriteCIDFontType0C(CStream* pOutputStream, unsigned short* pCodeToGID, unsigned int unCodesCount)
{
if (!m_bOpenTypeCFF)
{

View File

@ -377,7 +377,7 @@ namespace PdfWriter
// Записываем OpenType шрифт не меняя его
if (m_bOpenTypeCFF)
{
WriteCIDFontType0C(pOutputStream, pCodeToGID, unCodesCount, pUseGlyfs, lGlyfsCount);
WriteCIDFontType0C(pOutputStream, pCodeToGID, unCodesCount);
return;
}

View File

@ -100,7 +100,7 @@ namespace PdfWriter
// таблицу 'cmap'.
void WriteTTF(CStream* pOutputStream, char *sName = NULL, unsigned short *pCodeToGID = NULL, unsigned int unCodesCount = 0, unsigned char *pUseGlyfs = NULL, long lGlyfsCount = 0);
void WriteOTF(CStream* pOutputStream, char *sName = NULL, unsigned short *pCodeToGID = NULL);
void WriteCIDFontType0C(CStream* pOutputStream, unsigned short* pCodeToGID = NULL, unsigned int unCodesCount = 0, unsigned char* pUseGlyfs = NULL, long lGlyfsCount = 0);
void WriteCIDFontType0C(CStream* pOutputStream, unsigned short* pCodeToGID = NULL, unsigned int unCodesCount = 0);
int GetAscent();
int GetDescent();