Nicolas Pena | 4905840 | 2017-02-14 18:26:20 -0500 | [diff] [blame] | 1 | // Copyright 2017 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "public/fpdf_edit.h" |
| 6 | |
| 7 | #include "core/fpdfapi/cpdf_modulemgr.h" |
| 8 | #include "core/fpdfapi/font/cpdf_font.h" |
| 9 | #include "core/fpdfapi/page/cpdf_textobject.h" |
| 10 | #include "fpdfsdk/fsdk_define.h" |
| 11 | |
| 12 | DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPageObj_NewTextObj(FPDF_DOCUMENT document, |
| 13 | FPDF_BYTESTRING font, |
| 14 | float font_size) { |
| 15 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 16 | if (!pDoc) |
| 17 | return nullptr; |
| 18 | |
| 19 | CPDF_Font* pFont = CPDF_Font::GetStockFont(pDoc, CFX_ByteStringC(font)); |
| 20 | if (!pFont) |
| 21 | return nullptr; |
| 22 | |
| 23 | CPDF_TextObject* pTextObj = new CPDF_TextObject; |
| 24 | pTextObj->m_TextState.SetFont(pFont); |
| 25 | pTextObj->m_TextState.SetFontSize(font_size); |
| 26 | pTextObj->DefaultStates(); |
| 27 | return pTextObj; |
| 28 | } |
| 29 | |
| 30 | DLLEXPORT FPDF_BOOL STDCALL FPDFText_SetText(FPDF_PAGEOBJECT text_object, |
| 31 | FPDF_BYTESTRING text) { |
| 32 | if (!text_object) |
| 33 | return false; |
| 34 | |
| 35 | auto pTextObj = reinterpret_cast<CPDF_TextObject*>(text_object); |
| 36 | pTextObj->SetText(CFX_ByteString(text)); |
| 37 | return true; |
| 38 | } |