summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdf_text.cpp
diff options
context:
space:
mode:
authorNicolas Pena <npm@chromium.org>2018-08-17 19:54:23 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-08-17 19:54:23 +0000
commit1b2b76d634ba3716ee43a553cd952927a7d262a2 (patch)
treedc7faab94ae4a2caaad83c2b027819634cf48037 /fpdfsdk/fpdf_text.cpp
parente13a068f29061b9c6d24189bc4dc87a9111cdb1b (diff)
downloadpdfium-1b2b76d634ba3716ee43a553cd952927a7d262a2.tar.xz
Add FPDFText_GetFontInfo
Bug: pdfium:929 Change-Id: I9da03a1e317cff69ec4c76b69289cfa753b6bb77 Reviewed-on: https://pdfium-review.googlesource.com/40531 Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: Nicolás Peña Moreno <npm@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdf_text.cpp')
-rw-r--r--fpdfsdk/fpdf_text.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/fpdfsdk/fpdf_text.cpp b/fpdfsdk/fpdf_text.cpp
index d8d3b2675b..a39402eb72 100644
--- a/fpdfsdk/fpdf_text.cpp
+++ b/fpdfsdk/fpdf_text.cpp
@@ -10,7 +10,9 @@
#include <memory>
#include <vector>
+#include "core/fpdfapi/font/cpdf_font.h"
#include "core/fpdfapi/page/cpdf_page.h"
+#include "core/fpdfapi/page/cpdf_textobject.h"
#include "core/fpdfdoc/cpdf_viewerpreferences.h"
#include "core/fpdftext/cpdf_linkextract.h"
#include "core/fpdftext/cpdf_textpage.h"
@@ -88,6 +90,37 @@ FPDF_EXPORT double FPDF_CALLCONV FPDFText_GetFontSize(FPDF_TEXTPAGE text_page,
return charinfo.m_FontSize;
}
+FPDF_EXPORT unsigned long FPDF_CALLCONV
+FPDFText_GetFontInfo(FPDF_TEXTPAGE text_page,
+ int index,
+ void* buffer,
+ unsigned long buflen,
+ int* flags) {
+ if (!text_page)
+ return 0;
+ CPDF_TextPage* pTextObj = CPDFTextPageFromFPDFTextPage(text_page);
+
+ if (index < 0 || index >= pTextObj->CountChars())
+ return 0;
+
+ FPDF_CHAR_INFO charinfo;
+ pTextObj->GetCharInfo(index, &charinfo);
+ if (!charinfo.m_pTextObj)
+ return 0;
+
+ CPDF_Font* font = charinfo.m_pTextObj->GetFont();
+ if (!font)
+ return 0;
+
+ if (flags)
+ *flags = font->GetFontFlags();
+ ByteString basefont = font->GetBaseFont();
+ unsigned long length = basefont.GetLength() + 1;
+ if (buffer && buflen >= length)
+ memcpy(buffer, basefont.c_str(), length);
+ return length;
+}
+
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFText_GetCharBox(FPDF_TEXTPAGE text_page,
int index,
double* left,