summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfedittext.cpp
diff options
context:
space:
mode:
authorNicolas Pena <npm@chromium.org>2017-05-02 14:12:50 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-05-02 18:37:40 +0000
commitb31618571938e4873dcf1cdd44eeedb40caa5bd7 (patch)
treea337f11a62a35e8c0d52be8c5c9ec55902a6055a /fpdfsdk/fpdfedittext.cpp
parent336544a7451ac80c9f33216b7f61e9347d251108 (diff)
downloadpdfium-b31618571938e4873dcf1cdd44eeedb40caa5bd7.tar.xz
Add API to create a text object using a loaded font.
There is already a method to add text from standard font, this CL adds an option to add text using a loaded font. The font set into a text object is ref counted and may be released, so call LoadFont on this new text obj, and add a method to close the font. This CL also improves the SetText method so that it now uses a WideString, in preparation for CID fonts with non-Latin characters. Bug: pdfium:667 Change-Id: I6829d702357d2a898a12f5297e4fd2ec993a9891 Reviewed-on: https://pdfium-review.googlesource.com/4770 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Nicolás Peña <npm@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdfedittext.cpp')
-rw-r--r--fpdfsdk/fpdfedittext.cpp41
1 files changed, 39 insertions, 2 deletions
diff --git a/fpdfsdk/fpdfedittext.cpp b/fpdfsdk/fpdfedittext.cpp
index aec6050d21..f4e1d66bc1 100644
--- a/fpdfsdk/fpdfedittext.cpp
+++ b/fpdfsdk/fpdfedittext.cpp
@@ -8,6 +8,7 @@
#include "core/fpdfapi/cpdf_modulemgr.h"
#include "core/fpdfapi/font/cpdf_font.h"
#include "core/fpdfapi/font/cpdf_type1font.h"
+#include "core/fpdfapi/page/cpdf_docpagedata.h"
#include "core/fpdfapi/page/cpdf_textobject.h"
#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfapi/parser/cpdf_dictionary.h"
@@ -236,12 +237,20 @@ DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPageObj_NewTextObj(FPDF_DOCUMENT document,
}
DLLEXPORT FPDF_BOOL STDCALL FPDFText_SetText(FPDF_PAGEOBJECT text_object,
- FPDF_BYTESTRING text) {
+ FPDF_WIDESTRING text) {
if (!text_object)
return false;
auto* pTextObj = reinterpret_cast<CPDF_TextObject*>(text_object);
- pTextObj->SetText(CFX_ByteString(text));
+ FX_STRSIZE len = CFX_WideString::WStringLength(text);
+ CFX_WideString encodedText = CFX_WideString::FromUTF16LE(text, len);
+ CFX_ByteString byteText;
+ for (int i = 0; i < encodedText.GetLength(); ++i) {
+ uint32_t charcode =
+ pTextObj->GetFont()->CharCodeFromUnicode(encodedText[i]);
+ pTextObj->GetFont()->AppendChar(&byteText, charcode);
+ }
+ pTextObj->SetText(byteText);
return true;
}
@@ -267,3 +276,31 @@ DLLEXPORT FPDF_FONT STDCALL FPDFText_LoadFont(FPDF_DOCUMENT document,
return cid ? LoadCompositeFont(pDoc, std::move(pFont), data, size, font_type)
: LoadSimpleFont(pDoc, std::move(pFont), data, size, font_type);
}
+
+DLLEXPORT void STDCALL FPDFFont_Close(FPDF_FONT font) {
+ if (!font)
+ return;
+
+ CPDF_Font* cpdf_font = reinterpret_cast<CPDF_Font*>(font);
+ CPDF_Document* pDoc = cpdf_font->m_pDocument;
+ CPDF_DocPageData* pPageData = pDoc ? pDoc->GetPageData() : nullptr;
+ if (pPageData && !pPageData->IsForceClear())
+ pPageData->ReleaseFont(cpdf_font->GetFontDict());
+}
+
+DLLEXPORT FPDF_PAGEOBJECT STDCALL
+FPDFPageObj_CreateTextObj(FPDF_DOCUMENT document,
+ FPDF_FONT font,
+ float font_size) {
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+ if (!pDoc || !font)
+ return nullptr;
+
+ CPDF_Font* pFont = reinterpret_cast<CPDF_Font*>(font);
+
+ auto pTextObj = pdfium::MakeUnique<CPDF_TextObject>();
+ pTextObj->m_TextState.SetFont(pDoc->LoadFont(pFont->GetFontDict()));
+ pTextObj->m_TextState.SetFontSize(font_size);
+ pTextObj->DefaultStates();
+ return pTextObj.release();
+}