summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfedittext.cpp
diff options
context:
space:
mode:
authorNicolas Pena <npm@chromium.org>2017-02-14 18:26:20 -0500
committerChromium commit bot <commit-bot@chromium.org>2017-02-15 15:05:06 +0000
commit49058400ea8ddf753010dc73e7d381b7a35993ae (patch)
treedc6739a113c88129f6082f7f5ae7d10f99dde727 /fpdfsdk/fpdfedittext.cpp
parent1c467fd5145e7f61ab03b608cf9e9581022b4428 (diff)
downloadpdfium-49058400ea8ddf753010dc73e7d381b7a35993ae.tar.xz
Add public API for adding text with standard fonts
BUG=pdfium:667 Change-Id: I05e301385a7af4b6ce27dc0b885e23646abf3dd9 Reviewed-on: https://pdfium-review.googlesource.com/2711 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdfedittext.cpp')
-rw-r--r--fpdfsdk/fpdfedittext.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/fpdfsdk/fpdfedittext.cpp b/fpdfsdk/fpdfedittext.cpp
new file mode 100644
index 0000000000..79ca310f7c
--- /dev/null
+++ b/fpdfsdk/fpdfedittext.cpp
@@ -0,0 +1,38 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "public/fpdf_edit.h"
+
+#include "core/fpdfapi/cpdf_modulemgr.h"
+#include "core/fpdfapi/font/cpdf_font.h"
+#include "core/fpdfapi/page/cpdf_textobject.h"
+#include "fpdfsdk/fsdk_define.h"
+
+DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPageObj_NewTextObj(FPDF_DOCUMENT document,
+ FPDF_BYTESTRING font,
+ float font_size) {
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+ if (!pDoc)
+ return nullptr;
+
+ CPDF_Font* pFont = CPDF_Font::GetStockFont(pDoc, CFX_ByteStringC(font));
+ if (!pFont)
+ return nullptr;
+
+ CPDF_TextObject* pTextObj = new CPDF_TextObject;
+ pTextObj->m_TextState.SetFont(pFont);
+ pTextObj->m_TextState.SetFontSize(font_size);
+ pTextObj->DefaultStates();
+ return pTextObj;
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FPDFText_SetText(FPDF_PAGEOBJECT text_object,
+ FPDF_BYTESTRING text) {
+ if (!text_object)
+ return false;
+
+ auto pTextObj = reinterpret_cast<CPDF_TextObject*>(text_object);
+ pTextObj->SetText(CFX_ByteString(text));
+ return true;
+} \ No newline at end of file