summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfedittext.cpp
blob: 79ca310f7c15a7eb5bd9d1c732ff1037b08cc5f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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;
}