Fix pdf accuracy

This commit is contained in:
Svetlana Kulikova
2024-12-04 11:52:39 +03:00
parent d3a317ed4b
commit c0ca4189d3
5 changed files with 26 additions and 18 deletions

View File

@ -542,8 +542,8 @@ private:
}
if (m_nType == 0)
nRotate = ((CPdfFile*)m_pFile)->GetRotate(nPageIndex);
nWidth = dWidth;
nHeight = dHeight;
nWidth = round(dWidth);
nHeight = round(dHeight);
nPageDpiX = dPageDpiX;
}

View File

@ -506,8 +506,8 @@ function readAnnotAP(reader, AP)
{
// number for relations with AP
AP["i"] = reader.readInt();
AP["x"] = reader.readInt();
AP["y"] = reader.readInt();
AP["x"] = reader.readDouble();
AP["y"] = reader.readDouble();
AP["w"] = reader.readInt();
AP["h"] = reader.readInt();
let n = reader.readInt();

View File

@ -750,11 +750,11 @@ void ReadAnnotAP(BYTE* pWidgetsAP, int& i)
int nPathLength = READ_INT(pWidgetsAP + i);
i += 4;
std::cout << "X " << nPathLength << ", ";
std::cout << "X " << (double)nPathLength / 100.0 << ", ";
nPathLength = READ_INT(pWidgetsAP + i);
i += 4;
std::cout << "Y " << nPathLength << ", ";
std::cout << "Y " << (double)nPathLength / 100.0 << ", ";
int nWidgetWidth = READ_INT(pWidgetsAP + i);
i += 4;

View File

@ -3258,8 +3258,8 @@ void CAnnotAP::Init(PDFDoc* pdfDoc, NSFonts::IFontManager* pFontManager, CPdfFon
m_dCropX = pCropBox->x1;
m_dCropY = pCropBox->y1;
double dWidth = pdfDoc->getPageCropWidth(nPageIndex + 1);
double dHeight = pdfDoc->getPageCropHeight(nPageIndex + 1);
double dWidth = round(pdfDoc->getPageCropWidth(nPageIndex + 1));
double dHeight = round(pdfDoc->getPageCropHeight(nPageIndex + 1));
double dRasterW = (double)nRasterW * m_dRWScale;
double dRasterH = (double)nRasterH * m_dRHScale;
@ -3310,8 +3310,8 @@ void CAnnotAP::Init(PDFDoc* pdfDoc, NSFonts::IFontManager* pFontManager, CPdfFon
m_gfx = new Gfx(pdfDoc, m_pRendererOut, nPageIndex + 1, pPage->getAttrs()->getResourceDict(), 72.0, 72.0, &box, crop ? cropBox : (PDFRectangle *)NULL, 0, NULL, NULL);
// Координаты внешнего вида
m_nRx1 = (int)round((m_dx1 - m_dCropX) * m_dWScale) - 1;
m_nRy1 = dRasterH - (int)round((m_dy2 - m_dCropY) * m_dHScale) - 1;
m_dRx1 = (m_dx1 - m_dCropX) * m_dWScale - 1;
m_dRy1 = (pdfDoc->getPageCropHeight(nPageIndex + 1) - m_dy2 + m_dCropY) * m_dHScale - 1;
}
void CAnnotAP::Init(AcroFormField* pField)
{
@ -3437,6 +3437,10 @@ void CAnnotAP::Draw(PDFDoc* pdfDoc, Object* oAP, int nRasterH, int nBackgroundCo
AcroFormFieldType oType = pField->getAcroFormFieldType();
((GlobalParamsAdaptor*)globalParams)->setDrawFormField(true);
double dOffsetX = -(m_dx1 - m_dCropX) * m_dWScale + 1 + m_dWTale / 2;
double dOffsetY = (m_dy2 - m_dCropY) * m_dHScale - nRasterH + 1 + m_dHTale / 2;
nPageIndex++;
std::vector<const char*> arrAPName { "N", "D", "R" };
for (unsigned int j = 0; j < arrAPName.size(); ++j)
{
@ -3460,8 +3464,8 @@ void CAnnotAP::Draw(PDFDoc* pdfDoc, Object* oAP, int nRasterH, int nBackgroundCo
pView->sASName = oObj.dictGetKey(k);
if ((oType == acroFormFieldRadioButton || oType == acroFormFieldCheckbox) && pView->sASName != "Off")
pView->sASName = "Yes";
m_pRenderer->SetCoordTransformOffset(-(m_dx1 - m_dCropX) * m_dWScale + 1 + m_dWTale / 2, (m_dy2 - m_dCropY) * m_dHScale - nRasterH + 1 + m_dHTale / 2);
DrawAppearance(pdfDoc, nPageIndex + 1, pField, m_gfx, arrAPName[j], pView->sASName.c_str());
m_pRenderer->SetCoordTransformOffset(dOffsetX, dOffsetY);
DrawAppearance(pdfDoc, nPageIndex, pField, m_gfx, arrAPName[j], pView->sASName.c_str());
WriteAppearance(nBackgroundColor, pView);
pView->nBlendMode = GetBlendMode();
m_arrAP.push_back(pView);
@ -3471,8 +3475,8 @@ void CAnnotAP::Draw(PDFDoc* pdfDoc, Object* oAP, int nRasterH, int nBackgroundCo
{
CAnnotAPView* pView = new CAnnotAPView();
pView->sAPName = arrAPName[j];
m_pRenderer->SetCoordTransformOffset(-(m_dx1 - m_dCropX) * m_dWScale + 1 + m_dWTale / 2, (m_dy2 - m_dCropY) * m_dHScale - nRasterH + 1 + m_dHTale / 2);
DrawAppearance(pdfDoc, nPageIndex + 1, pField, m_gfx, arrAPName[j], NULL);
m_pRenderer->SetCoordTransformOffset(dOffsetX, dOffsetY);
DrawAppearance(pdfDoc, nPageIndex, pField, m_gfx, arrAPName[j], NULL);
WriteAppearance(nBackgroundColor, pView);
pView->nBlendMode = GetBlendMode();
m_arrAP.push_back(pView);
@ -3490,6 +3494,9 @@ void CAnnotAP::Draw(PDFDoc* pdfDoc, Object* oAP, int nRasterH, int nBackgroundCo
XRef* xref = pdfDoc->getXRef();
oAnnotRef->fetch(xref, &oAnnot);
double dOffsetX = -(m_dx1 - m_dCropX) * m_dWScale + 1 + m_dWTale / 2;
double dOffsetY = (m_dy2 - m_dCropY) * m_dHScale - (double)nRasterH * m_dRHScale + 1 + m_dHTale / 2;
std::vector<const char*> arrAPName { "N", "D", "R" };
for (unsigned int j = 0; j < arrAPName.size(); ++j)
{
@ -3501,7 +3508,7 @@ void CAnnotAP::Draw(PDFDoc* pdfDoc, Object* oAP, int nRasterH, int nBackgroundCo
CAnnotAPView* pView = new CAnnotAPView();
pView->sAPName = arrAPName[j];
m_pRenderer->SetCoordTransformOffset(-(m_dx1 - m_dCropX) * m_dWScale + 1 + m_dWTale / 2, (m_dy2 - m_dCropY) * m_dHScale - (double)nRasterH * m_dRHScale + 1 + m_dHTale / 2);
m_pRenderer->SetCoordTransformOffset(dOffsetX, dOffsetY);
Ref ref = oAnnotRef->getRef();
Annot* annot = new Annot(pdfDoc, oAnnot.getDict(), &ref, arrAPName[j]);
@ -3554,8 +3561,8 @@ void CAnnotAP::ToWASM(NSWasm::CData& oRes)
return;
oRes.AddInt(m_unRefNum);
oRes.AddInt(m_nRx1);
oRes.AddInt(m_nRy1);
oRes.AddDouble(m_dRx1);
oRes.AddDouble(m_dRy1);
oRes.AddInt(m_nWidth);
oRes.AddInt(m_nHeight);
oRes.AddInt((unsigned int)m_arrAP.size());

View File

@ -147,7 +147,8 @@ private:
double m_dWScale, m_dHScale;
double m_dRWScale, m_dRHScale;
double m_dWTale, m_dHTale;
int m_nRx1, m_nRy1, m_nWidth, m_nHeight;
double m_dRx1, m_dRy1;
int m_nWidth, m_nHeight;
std::vector<CAnnotAPView*> m_arrAP;
bool m_bIsStamp;