diff --git a/core/fpdfapi/page/cpdf_imageobject.cpp b/core/fpdfapi/page/cpdf_imageobject.cpp index 3b5a740..58ef90a 100644 --- a/core/fpdfapi/page/cpdf_imageobject.cpp +++ b/core/fpdfapi/page/cpdf_imageobject.cpp @@ -43,6 +43,7 @@ const CPDF_ImageObject* CPDF_ImageObject::AsImage() const { void CPDF_ImageObject::CalcBoundingBox() { std::tie(m_Left, m_Right, m_Top, m_Bottom) = m_Matrix.TransformRect(0.f, 1.f, 1.f, 0.f); + fprintf(stderr, "Image BB: %f, %f, %f, %f\n", m_Left, m_Right, m_Top, m_Bottom); } void CPDF_ImageObject::SetImage(const RetainPtr& pImage) { diff --git a/core/fpdfapi/page/cpdf_pageobject.cpp b/core/fpdfapi/page/cpdf_pageobject.cpp index 8bb5bf5..9b5e2ce 100644 --- a/core/fpdfapi/page/cpdf_pageobject.cpp +++ b/core/fpdfapi/page/cpdf_pageobject.cpp @@ -98,5 +98,7 @@ FX_RECT CPDF_PageObject::GetBBox(const CFX_Matrix* pMatrix) const { if (pMatrix) rect = pMatrix->TransformRect(rect); + FX_RECT rc = rect.GetOuterRect(); + fprintf(stderr, "PageObject BB: %f, %f, %f, %f\n", rc.left, rc.right, rc.top, rc.bottom); return rect.GetOuterRect(); } diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp index 0a01ae0..fad2920 100644 --- a/core/fpdfapi/render/cpdf_renderstatus.cpp +++ b/core/fpdfapi/render/cpdf_renderstatus.cpp @@ -1793,6 +1793,7 @@ bool CPDF_RenderStatus::ProcessText(CPDF_TextObject* textobj, return true; float font_size = textobj->m_TextState.GetFontSize(); + fprintf(stderr, "Font size: %f, matrix a: %f, b: %f, c: %f, d: %f, e: %f, f: %f\n", font_size, text_matrix.a, text_matrix.b, text_matrix.c, text_matrix.d, text_matrix.e, text_matrix.f); if (bPattern) { DrawTextPathWithPattern(textobj, pObj2Device, pFont, font_size, &text_matrix, bFill, bStroke); diff --git a/fpdfsdk/fpdfeditimg.cpp b/fpdfsdk/fpdfeditimg.cpp index 0d7ba56..37bdf99 100644 --- a/fpdfsdk/fpdfeditimg.cpp +++ b/fpdfsdk/fpdfeditimg.cpp @@ -167,6 +167,26 @@ FPDFImageObj_GetBitmap(FPDF_PAGEOBJECT image_object) { return pBitmap.Leak(); } +FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV +FPDFImageObj_GetBitmapBgra(FPDF_PAGEOBJECT image_object) { + CPDF_PageObject* pObj = CPDFPageObjectFromFPDFPageObject(image_object); + if (!pObj || !pObj->IsImage()) + return nullptr; + + RetainPtr pImg = pObj->AsImage()->GetImage(); + if (!pImg) + return nullptr; + + RetainPtr pSource = pImg->LoadDIBSource(); + if (!pSource) + return nullptr; + + RetainPtr pBitmap; + pBitmap = pSource->CloneConvert(FXDIB_Argb); + + return pBitmap.Leak(); +} + FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFImageObj_GetImageDataDecoded(FPDF_PAGEOBJECT image_object, void* buffer, diff --git a/fpdfsdk/fpdfeditpage.cpp b/fpdfsdk/fpdfeditpage.cpp index ca2cf3f..ac36788 100644 --- a/fpdfsdk/fpdfeditpage.cpp +++ b/fpdfsdk/fpdfeditpage.cpp @@ -11,12 +11,14 @@ #include #include "core/fpdfapi/edit/cpdf_pagecontentgenerator.h" +#include "core/fpdfapi/font/cpdf_font.h" #include "core/fpdfapi/page/cpdf_form.h" #include "core/fpdfapi/page/cpdf_formobject.h" #include "core/fpdfapi/page/cpdf_imageobject.h" #include "core/fpdfapi/page/cpdf_page.h" #include "core/fpdfapi/page/cpdf_pageobject.h" #include "core/fpdfapi/page/cpdf_pathobject.h" +#include "core/fpdfapi/page/cpdf_textobject.h" #include "core/fpdfapi/page/cpdf_shadingobject.h" #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_document.h" @@ -363,3 +365,103 @@ FPDFPageObj_GetBounds(FPDF_PAGEOBJECT pageObject, *top = bbox.top; return true; } + +FPDF_EXPORT int FPDF_CALLCONV +FPDFTextObj_CountChars(FPDF_PAGEOBJECT text_object) +{ + if (!text_object) + return 0; + + CPDF_TextObject* pTxtObj = static_cast(text_object); + return pTxtObj->CountChars(); +} + +FPDF_EXPORT int FPDF_CALLCONV +FPDFTextObj_GetFontSize(FPDF_PAGEOBJECT text_object) +{ + if (!text_object) + return 0; + + CPDF_TextObject* pTxtObj = static_cast(text_object); + return pTxtObj->GetFontSize(); +} + +FPDF_EXPORT void FPDF_CALLCONV +FPDFTextObj_GetMatrix(FPDF_PAGEOBJECT text_object, + double* a, + double* b, + double* c, + double* d) { + if (!text_object) + return; + + CPDF_TextObject* pTxtObj = static_cast(text_object); + const CFX_Matrix& matrix = pTxtObj->GetTextMatrix(); + *a = matrix.a; + *b = matrix.b; + *c = matrix.c; + *d = matrix.d; +} + +FPDF_EXPORT int FPDF_CALLCONV +FPDFTextObj_GetUnicode(FPDF_PAGEOBJECT text_object, int index) +{ + if (!text_object || index < 0) + return 0; + + CPDF_TextObject* pTxtObj = static_cast(text_object); + if (index > pTxtObj->CountChars()) + return 0; + + CPDF_TextObjectItem info; + pTxtObj->GetCharInfo(index, &info); + return info.m_CharCode; +} + +FPDF_EXPORT int FPDF_CALLCONV FPDFTextObj_GetText(FPDF_PAGEOBJECT text_object, + int char_start, + int char_count, + unsigned short* result) { + if (!text_object || char_start < 0 || char_count < 0 || !result) + return 0; + + CPDF_TextObject* pTxtObj = static_cast(text_object); + int char_available = pTxtObj->CountChars() - char_start; + if (char_available <= 0) + return 0; + + char_count = std::min(char_count, char_available); + if (char_count == 0) { + // Writing out "", which has a character count of 1 due to the NUL. + *result = '\0'; + return 1; + } + + CPDF_Font* pFont = pTxtObj->GetFont(); + WideString str; + for (uint32_t charcode : pTxtObj->GetCharCodes()) { + if (charcode != CPDF_Font::kInvalidCharCode) + str += pFont->UnicodeFromCharCode(charcode); + } + +// CFX_WideTextBuf m_TextBuf; +// WideString str = textpage->GetPageText(char_start, char_count); +// return WideString(m_TextBuf.AsStringView().Mid( +// static_cast(text_start), static_cast(text_count))); + +// if (str.GetLength() > static_cast(char_count)) +// str = str.Left(static_cast(char_count)); + + // Reincode in UTF-16. +// WideString str = text.UTF8Decode(); + + // UFT16LE_Encode doesn't handle surrogate pairs properly, so it is expected + // the number of items to stay the same. + ByteString byte_str = str.UTF16LE_Encode(); + size_t byte_str_len = byte_str.GetLength(); + int ret_count = byte_str_len / sizeof(unsigned short); + + ASSERT(ret_count <= char_count + 1); // +1 to account for the NUL terminator. + memcpy(result, byte_str.GetBuffer(byte_str_len), byte_str_len); + return ret_count; +} diff --git a/fpdfsdk/fpdftext.cpp b/fpdfsdk/fpdftext.cpp index 68bf4f8..e073b20 100644 --- a/fpdfsdk/fpdftext.cpp +++ b/fpdfsdk/fpdftext.cpp @@ -105,6 +105,28 @@ FPDF_EXPORT double FPDF_CALLCONV FPDFText_GetFontSize(FPDF_TEXTPAGE text_page, return charinfo.m_FontSize; } +FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFText_GetMatrix(FPDF_TEXTPAGE text_page, + int index, + double* a, + double* b, + double* c, + double* d) { + if (!text_page || index < 0) + return false; + + CPDF_TextPage* textpage = CPDFTextPageFromFPDFTextPage(text_page); + if (index >= textpage->CountChars()) + return false; + + FPDF_CHAR_INFO charinfo; + textpage->GetCharInfo(index, &charinfo); + *a = charinfo.m_Matrix.a; + *b = charinfo.m_Matrix.b; + *c = charinfo.m_Matrix.c; + *d = charinfo.m_Matrix.d; + return true; +} + FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFText_GetCharBox(FPDF_TEXTPAGE text_page, int index, double* left, diff --git a/public/fpdf_edit.h b/public/fpdf_edit.h index 54735a3..a9c1a25 100644 --- a/public/fpdf_edit.h +++ b/public/fpdf_edit.h @@ -761,6 +761,57 @@ FPDFPageObj_CreateTextObj(FPDF_DOCUMENT document, FPDF_FONT font, float font_size); +// Get the number of characters from a text object. +// +// text_object - Handle of text object returned by FPDFPageObj_NewTextObj +// or FPDFPageObj_NewTextObjEx. +// Return Value: +// A character count in the text object. +FPDF_EXPORT int FPDF_CALLCONV +FPDFTextObj_CountChars(FPDF_PAGEOBJECT text_object); + + +// Get the font size of a text object. +// +// text_object - Handle of text object returned by FPDFPageObj_NewTextObj +// or FPDFPageObj_NewTextObjEx. +// +// Return Value: +// The value of the font size +FPDF_EXPORT int FPDF_CALLCONV +FPDFTextObj_GetFontSize(FPDF_PAGEOBJECT text_object); + +// Get the matrix of a particular text object. +// +// text_object - Handle of text object returned by FPDFPageObj_NewTextObj +// or FPDFPageObj_NewTextObjEx. +// a - Pointer to a double value receiving coefficient "a" of the matrix. +// b - Pointer to a double value receiving coefficient "b" of the matrix. +// c - Pointer to a double value receiving coefficient "c" of the matrix. +// d - Pointer to a double value receiving coefficient "d" of the matrix. +FPDF_EXPORT void FPDF_CALLCONV +FPDFTextObj_GetMatrix(FPDF_PAGEOBJECT text_object, + double* a, + double* b, + double* c, + double* d); + +// Get the unicode of a special character in a text object. +// +// text_object - Handle of text object returned by FPDFPageObj_NewTextObj +// or FPDFPageObj_NewTextObjEx. +// index - The index of the character to get the unicode. +// Return Value: +// The unicode value. +FPDF_EXPORT int FPDF_CALLCONV +FPDFTextObj_GetUnicode(FPDF_PAGEOBJECT text_object, int index); + +FPDF_EXPORT int FPDF_CALLCONV +FPDFTextObj_GetText(FPDF_PAGEOBJECT text_object, + int char_start, + int char_count, + unsigned short* result); + #ifdef __cplusplus } // extern "C" #endif // __cplusplus diff --git a/public/fpdf_text.h b/public/fpdf_text.h index 043dc16..fe3b971 100644 --- a/public/fpdf_text.h +++ b/public/fpdf_text.h @@ -342,6 +342,26 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFText_GetSchCount(FPDF_SCHHANDLE handle); // FPDF_EXPORT void FPDF_CALLCONV FPDFText_FindClose(FPDF_SCHHANDLE handle); +// Get the matrix of a particular character. +// +// text_page - Handle to a text page information structure. +// Returned by FPDFText_LoadPage function. +// index - Zero-based index of the character +// a - Pointer to a double value receiving coefficient "a" of the matrix. +// b - Pointer to a double value receiving coefficient "b" of the matrix. +// c - Pointer to a double value receiving coefficient "c" of the matrix. +// d - Pointer to a double value receiving coefficient "d" of the matrix. +// +// Return Value: +// On success, return TRUE and fill in |a|, |b|, |c|, and |d| +FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV +FPDFText_GetMatrix(FPDF_TEXTPAGE text_page, + int index, + double* a, + double* b, + double* c, + double* d); + // Function: FPDFLink_LoadWebLinks // Prepare information about weblinks in a page. // Parameters: diff --git a/public/fpdfview.h b/public/fpdfview.h index 35e87ae..80ab0ad 100644 --- a/public/fpdfview.h +++ b/public/fpdfview.h @@ -908,6 +908,9 @@ FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV FPDFBitmap_CreateEx(int width, // function; see the list of such formats above. FPDF_EXPORT int FPDF_CALLCONV FPDFBitmap_GetFormat(FPDF_BITMAP bitmap); +FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV +FPDFImageObj_GetBitmapBgra(FPDF_PAGEOBJECT image_object); + // Function: FPDFBitmap_FillRect // Fill a rectangle in a bitmap. // Parameters: