Skip to content

Commit

Permalink
bug: error in displaying certain characthers (#240)
Browse files Browse the repository at this point in the history
when using cntrmask at the beginning of the glyp one can optimize and use it as vstem as well.

the reading implementation did not consider this and didnt count stems when arguments are provided to cntrmask.

for hintmask it was doing that.
  • Loading branch information
galkahana authored Dec 26, 2023
1 parent 8c2251a commit 4ed314d
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 9 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ xcode/Build
xcode/DerivedData
.DS_Store

#VSCode unswated#
#################
.vscode

#unwanted other sources #
########################
zlib-1.2.3
Expand Down
32 changes: 32 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(ctest lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${cmake.testProgram}",
"args": [ "${cmake.testArgs}" ],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb"
},
{
"name": "(ctest msvc) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "${cmake.testProgram}",
"args": [ "${cmake.testArgs}" ],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "integratedTerminal"
}

]
}
73 changes: 73 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"files.associations": {
"string": "cpp",
"iosfwd": "cpp",
"vector": "cpp",
"list": "cpp",
"__bit_reference": "cpp",
"__bits": "cpp",
"__config": "cpp",
"__debug": "cpp",
"__errc": "cpp",
"__hash_table": "cpp",
"__locale": "cpp",
"__mutex_base": "cpp",
"__node_handle": "cpp",
"__nullptr": "cpp",
"__split_buffer": "cpp",
"__string": "cpp",
"__threading_support": "cpp",
"__tree": "cpp",
"__tuple": "cpp",
"array": "cpp",
"atomic": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"complex": "cpp",
"concepts": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"exception": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"locale": "cpp",
"map": "cpp",
"memory": "cpp",
"mutex": "cpp",
"new": "cpp",
"optional": "cpp",
"ostream": "cpp",
"ratio": "cpp",
"set": "cpp",
"sstream": "cpp",
"stack": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"variant": "cpp",
"algorithm": "cpp",
"tiffio.h": "c"
}
}
2 changes: 2 additions & 0 deletions PDFWriter/CharStringType2Flattener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ EStatusCode CharStringType2Flattener::WriteStemMask(Byte* inProgramCounter)

EStatusCode CharStringType2Flattener::Type2Cntrmask(const CharStringOperandList& inOperandList,Byte* inProgramCounter)
{
mStemsCount+= (unsigned short)(inOperandList.size() / 2);

if(WriteRegularOperator(20) != PDFHummus::eSuccess)
return PDFHummus::eFailure;

Expand Down
4 changes: 3 additions & 1 deletion PDFWriter/CharStringType2Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ Byte* CharStringType2Interpreter::InterpretHStemHM(Byte* inProgramCounter)

Byte* CharStringType2Interpreter::InterpretHintMask(Byte* inProgramCounter)
{
mStemsCount+= (unsigned short)(mOperandStack.size() / 2);
mStemsCount+= (unsigned short)(mOperandStack.size() / 2); // assuming this is a shortcut of dropping vstem if got arguments

EStatusCode status = mImplementationHelper->Type2Hintmask(mOperandStack,inProgramCounter);
if(status != PDFHummus::eSuccess)
Expand All @@ -528,6 +528,8 @@ Byte* CharStringType2Interpreter::InterpretHintMask(Byte* inProgramCounter)

Byte* CharStringType2Interpreter::InterpretCntrMask(Byte* inProgramCounter)
{
mStemsCount+= (unsigned short)(mOperandStack.size() / 2); // assuming this is a shortcut of dropping vstem if got arguments

EStatusCode status = mImplementationHelper->Type2Cntrmask(mOperandStack,inProgramCounter);
if(status != PDFHummus::eSuccess)
return NULL;
Expand Down
12 changes: 9 additions & 3 deletions PDFWriter/CharStringType2Tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,24 @@ void CharStringType2Tracer::WriteStemMask(Byte* inProgramCounter)
unsigned short maskSize = mStemsCount/8 + (mStemsCount % 8 != 0 ? 1:0);
char buffer[3];

mWriter->Write((const Byte*)"(0x",1);
mWriter->Write((const Byte*)"(",1);
for(unsigned short i=0;i<maskSize;++i)
{
SAFE_SPRINTF_1(buffer,3,"%X",inProgramCounter[i]);
mWriter->Write((const Byte*)buffer,2);
Byte arg = inProgramCounter[i];
// writing as binary so it's easy to understand which stems are active and which ain't (used to write hex)
for(int j=7;j>=0;--j) {
SAFE_SPRINTF_1(buffer,3,"%d",(arg>>j) & 1);
mWriter->Write((const Byte*)buffer,1);
}
}

mWriter->Write((const Byte*)")",1);
}

EStatusCode CharStringType2Tracer::Type2Cntrmask(const CharStringOperandList& inOperandList,Byte* inProgramCounter)
{
mStemsCount+= (unsigned short)(inOperandList.size() / 2);

WriteStemMask(inProgramCounter);
mPrimitiveWriter.WriteKeyword("cntrmask");
return PDFHummus::eSuccess;
Expand Down
Binary file not shown.
72 changes: 71 additions & 1 deletion PDFWriterTesting/TextUsageBugs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3858,6 +3858,68 @@ static EStatusCode RunCNRS2Test(char* argv[]) {
return status;
}

static EStatusCode NotoSerifCJKRegularFontTest(char* argv[]) {
EStatusCode status = eSuccess;
PDFWriter pdfWriter;

do
{
status = pdfWriter.StartPDF(BuildRelativeOutputPath(argv, "NotoSerifCJKRegularFontTest.pdf"),
ePDFVersion14,
LogConfiguration(true, true,
BuildRelativeOutputPath(argv, "NotoSerifCJKRegularFontTest.log")));
if (status != eSuccess)
{
cout << "Failed to start file\n";
break;
}

PDFPage* page = new PDFPage();
page->SetMediaBox(PDFRectangle(0, 0, 595, 842));

PageContentContext* cxt = pdfWriter.StartPageContentContext(page);

AbstractContentContext::TextOptions textOptions(pdfWriter.GetFontForFile(
BuildRelativeInputPath(
argv,
"fonts/NotoSerifCJK-Regular.ttc")),
14,
AbstractContentContext::eGray,
0);

cxt->WriteText(10, 400, "\xE9\xBB\x98", textOptions);

status = pdfWriter.EndPageContentContext(cxt);
if (status != eSuccess)
{
status = PDFHummus::eFailure;
cout << "Failed to end content context\n";
break;
}

status = pdfWriter.WritePageAndRelease(page);
if (status != eSuccess)
{
status = PDFHummus::eFailure;
cout << "Failed to write page\n";
break;
}


status = pdfWriter.EndPDF();
if (status != eSuccess)
{
status = PDFHummus::eFailure;
cout << "Failed to end pdf\n";
break;
}

} while (false);


return status;
}


int TextUsageBugs(int argc, char* argv[])
{
Expand Down Expand Up @@ -3900,7 +3962,15 @@ int TextUsageBugs(int argc, char* argv[])
break;
}

status = NotoSerifCJKRegularFontTest(argv);
if (status != PDFHummus::eSuccess)
{
cout << "Error in RunNotoSerifCHKRegularFontTest\n";
status = PDFHummus::eFailure;
break;
}

} while(false);
return status;
return status == eSuccess ? 0:1;
}

0 comments on commit 4ed314d

Please sign in to comment.