summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Abd-El-Malek <jam@chromium.org>2015-01-30 16:55:08 -0800
committerJohn Abd-El-Malek <jam@chromium.org>2015-01-30 16:55:08 -0800
commit71c24b839498fb89184002ed30fcff353e1e402c (patch)
treec83e6b8231a550b00c0c20de290739e6ff35619c
parentb38a900497ab85c5badd5f1cd1f8c00d0c6f580d (diff)
downloadpdfium-71c24b839498fb89184002ed30fcff353e1e402c.tar.xz
Use system FreeType on Linux.
This saves 406KB in the binary size of the plugin. More importantly, it gets rid of the linker flag preventing bundling PDFium into the Chromium binary. BUG=453844 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/826613004
-rw-r--r--BUILD.gn24
-rw-r--r--core/include/fxge/fx_freetype.h15
-rw-r--r--core/src/fxge/ge/fx_ge_text.cpp14
-rw-r--r--pdfium.gyp36
4 files changed, 57 insertions, 32 deletions
diff --git a/BUILD.gn b/BUILD.gn
index efabf9f9e2..9c58b0396c 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -6,13 +6,15 @@ import("//testing/test.gni")
pdf_use_skia = false
+declare_args() {
+ # On Android there's no system FreeType. On Windows and Mac, only a few
+ # methods are used from it.
+ bundle_freetype = !is_linux
+}
+
config("pdfium_config") {
cflags = []
- include_dirs = [
- "third_party/freetype/include"
- ]
defines = [
- "FT2_BUILD_LIBRARY",
"_FPDFSDK_LIB",
"_NO_GDIPLUS_", # workaround text rendering issues on Windows
"OPJ_STATIC",
@@ -40,6 +42,13 @@ config("pdfium_config") {
"/wd4345",
]
}
+
+ if (bundle_freetype) {
+ include_dirs = [ "third_party/freetype/include" ]
+ defines += [ "FT2_BUILD_LIBRARY" ]
+ } else {
+ include_dirs = [ "/usr/include/freetype2" ]
+ }
}
static_library("pdfium") {
@@ -92,7 +101,6 @@ static_library("pdfium") {
deps = [
"third_party:bigint",
- "third_party:freetype",
"third_party:safemath",
":fdrm",
":formfiller",
@@ -115,6 +123,12 @@ static_library("pdfium") {
if (is_mac) {
libs += [ "AppKit.framework", "CoreFoundation.framework" ]
}
+
+ if (bundle_freetype) {
+ deps += [ "third_party:freetype" ]
+ } else {
+ libs += [ "freetype" ]
+ }
}
# Targets below this are only visible within this file.
diff --git a/core/include/fxge/fx_freetype.h b/core/include/fxge/fx_freetype.h
index 6419c6b6c2..4b49d5f6ea 100644
--- a/core/include/fxge/fx_freetype.h
+++ b/core/include/fxge/fx_freetype.h
@@ -4,12 +4,13 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#include "../../../third_party/freetype/include/ft2build.h"
-#include "../../../third_party/freetype/include/freetype.h"
-#include "../../../third_party/freetype/include/ftoutln.h"
-#include "../../../third_party/freetype/include/ftmm.h"
-#include "../../../third_party/freetype/include/internal/ftobjs.h"
-#include "../../../third_party/freetype/include/tttables.h"
+#include <ft2build.h>
+#include <freetype.h>
+#include <ftglyph.h>
+#include <ftlcdfil.h>
+#include <ftmm.h>
+#include <ftoutln.h>
+#include <tttables.h>
#ifdef __cplusplus
extern "C" {
#endif
@@ -111,8 +112,6 @@ typedef FT_CharMap FXFT_CharMap;
#define FXFT_Get_MM_Axis_Min(axis) ((FT_Var_Axis*)axis)->minimum
#define FXFT_Get_MM_Axis_Max(axis) ((FT_Var_Axis*)axis)->maximum
#define FXFT_Get_MM_Axis_Def(axis) ((FT_Var_Axis*)axis)->def
-#define FXFT_Get_Face_Internal_Flag(face) ((FT_Face)face)->internal->transform_flags
-#define FXFT_Set_Face_Internal_Flag(face, flag) (((FT_Face)face)->internal->transform_flags = flag)
#define FXFT_Alloc(library, size) ((FT_Library)library)->memory->alloc(((FT_Library)library)->memory, size)
#define FXFT_Free(face, p) ((FT_Face)face)->memory->free(((FT_Face)face)->memory, p)
#define FXFT_Get_Glyph_Outline(face) &((FT_Face)face)->glyph->outline
diff --git a/core/src/fxge/ge/fx_ge_text.cpp b/core/src/fxge/ge/fx_ge_text.cpp
index eb9b7d0a13..aca739afae 100644
--- a/core/src/fxge/ge/fx_ge_text.cpp
+++ b/core/src/fxge/ge/fx_ge_text.cpp
@@ -1332,12 +1332,10 @@ CFX_GlyphBitmap* CFX_FaceCache::RenderGlyph(CFX_Font* pFont, FX_DWORD glyph_inde
pFont->AdjustMMParams(glyph_index, dest_width, pFont->GetSubstFont()->m_Weight);
}
}
- int transflag = FXFT_Get_Face_Internal_Flag(m_Face);
FXFT_Set_Transform(m_Face, &ft_matrix, 0);
int load_flags = (m_Face->face_flags & FT_FACE_FLAG_SFNT) ? FXFT_LOAD_NO_BITMAP : (FXFT_LOAD_NO_BITMAP | FT_LOAD_NO_HINTING);
int error = FXFT_Load_Glyph(m_Face, glyph_index, load_flags);
if (error) {
- FXFT_Set_Face_Internal_Flag(m_Face, transflag);
return NULL;
}
int weight = 0;
@@ -1349,7 +1347,6 @@ CFX_GlyphBitmap* CFX_FaceCache::RenderGlyph(CFX_Font* pFont, FX_DWORD glyph_inde
if (pSubstFont && !(pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) && weight > 400) {
int index = (weight - 400) / 10;
if (index >= WEIGHTPOW_ARRAY_SIZE) {
- FXFT_Set_Face_Internal_Flag(m_Face, transflag);
return NULL;
}
int level = 0;
@@ -1363,13 +1360,11 @@ CFX_GlyphBitmap* CFX_FaceCache::RenderGlyph(CFX_Font* pFont, FX_DWORD glyph_inde
FXFT_Library_SetLcdFilter(CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary, FT_LCD_FILTER_DEFAULT);
error = FXFT_Render_Glyph(m_Face, anti_alias);
if (error) {
- FXFT_Set_Face_Internal_Flag(m_Face, transflag);
return NULL;
}
int bmwidth = FXFT_Get_Bitmap_Width(FXFT_Get_Glyph_Bitmap(m_Face));
int bmheight = FXFT_Get_Bitmap_Rows(FXFT_Get_Glyph_Bitmap(m_Face));
if (bmwidth > 2048 || bmheight > 2048) {
- FXFT_Set_Face_Internal_Flag(m_Face, transflag);
return NULL;
}
int dib_width = bmwidth;
@@ -1406,7 +1401,6 @@ CFX_GlyphBitmap* CFX_FaceCache::RenderGlyph(CFX_Font* pFont, FX_DWORD glyph_inde
_GammaAdjust(pDestBuf, bmwidth, bmheight, dest_pitch, CFX_GEModule::Get()->GetTextGammaTable());
}
}
- FXFT_Set_Face_Internal_Flag(m_Face, transflag);
return pGlyphBitmap;
}
FX_BOOL _OutputGlyph(void* dib, int x, int y, CFX_Font* pFont,
@@ -1448,7 +1442,6 @@ FX_BOOL OutputText(void* dib, int x, int y, CFX_Font* pFont, double font_size,
}
FXFT_Face face = pFont->GetFace();
FXFT_Select_Charmap(pFont->m_Face, FXFT_ENCODING_UNICODE);
- int transflag = FXFT_Get_Face_Internal_Flag(pFont->m_Face);
if (pText_matrix) {
FXFT_Matrix ft_matrix;
ft_matrix.xx = (signed long)(pText_matrix->a / 64 * 65536);
@@ -1476,7 +1469,6 @@ FX_BOOL OutputText(void* dib, int x, int y, CFX_Font* pFont, double font_size,
glyph_index, argb);
x_pos += (FX_FLOAT)w / em;
}
- FXFT_Set_Face_Internal_Flag(pFont->m_Face, transflag);
return TRUE;
}
FX_BOOL OutputGlyph(void* dib, int x, int y, CFX_Font* pFont, double font_size,
@@ -1493,11 +1485,9 @@ FX_BOOL OutputGlyph(void* dib, int x, int y, CFX_Font* pFont, double font_size,
ft_matrix.xy = ft_matrix.yx = 0;
ft_matrix.yy = (signed long)(font_size / 64 * 65536);
}
- int transflag = FXFT_Get_Face_Internal_Flag(pFont->m_Face);
FXFT_Set_Transform(pFont->m_Face, &ft_matrix, 0);
FX_BOOL ret = _OutputGlyph(dib, x, y, pFont,
glyph_index, argb);
- FXFT_Set_Face_Internal_Flag(pFont->m_Face, transflag);
return ret;
}
const CFX_PathData* CFX_FaceCache::LoadGlyphPath(CFX_Font* pFont, FX_DWORD glyph_index, int dest_width)
@@ -1644,12 +1634,10 @@ CFX_PathData* CFX_Font::LoadGlyphPath(FX_DWORD glyph_index, int dest_width)
AdjustMMParams(glyph_index, dest_width, m_pSubstFont->m_Weight);
}
}
- int transflag = FXFT_Get_Face_Internal_Flag(m_Face);
FXFT_Set_Transform(m_Face, &ft_matrix, 0);
int load_flags = (m_Face->face_flags & FT_FACE_FLAG_SFNT) ? FXFT_LOAD_NO_BITMAP : FXFT_LOAD_NO_BITMAP | FT_LOAD_NO_HINTING;
int error = FXFT_Load_Glyph(m_Face, glyph_index, load_flags);
if (error) {
- FXFT_Set_Face_Internal_Flag(m_Face, transflag);
return NULL;
}
if (m_pSubstFont && !(m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) && m_pSubstFont->m_Weight > 400) {
@@ -1676,7 +1664,6 @@ CFX_PathData* CFX_Font::LoadGlyphPath(FX_DWORD glyph_index, int dest_width)
params.m_PointCount = 0;
FXFT_Outline_Decompose(FXFT_Get_Glyph_Outline(m_Face), &funcs, &params);
if (params.m_PointCount == 0) {
- FXFT_Set_Face_Internal_Flag(m_Face, transflag);
return NULL;
}
CFX_PathData* pPath = FX_NEW CFX_PathData;
@@ -1695,7 +1682,6 @@ CFX_PathData* CFX_Font::LoadGlyphPath(FX_DWORD glyph_index, int dest_width)
if (params.m_PointCount) {
pPath->GetPoints()[params.m_PointCount - 1].m_Flag |= FXPT_CLOSEFIGURE;
}
- FXFT_Set_Face_Internal_Flag(m_Face, transflag);
return pPath;
}
void _CFX_UniqueKeyGen::Generate(int count, ...)
diff --git a/pdfium.gyp b/pdfium.gyp
index cbdf4b70ac..8b13321ab9 100644
--- a/pdfium.gyp
+++ b/pdfium.gyp
@@ -1,21 +1,37 @@
{
'variables': {
'pdf_use_skia%': 0,
+ 'conditions': [
+ ['OS=="linux"', {
+ 'bundle_freetype%': 0,
+ }, { # On Android there's no system FreeType. On Windows and Mac, only a
+ # few methods are used from it.
+ 'bundle_freetype%': 1,
+ }],
+ ],
},
'target_defaults': {
'defines' : [
- 'FT2_BUILD_LIBRARY',
'_FPDFSDK_LIB',
'_NO_GDIPLUS_', # workaround text rendering issues on Windows
'OPJ_STATIC',
],
- 'include_dirs': [
- 'third_party/freetype/include',
- ],
'conditions': [
['pdf_use_skia==1', {
'defines': ['_SKIA_SUPPORT_'],
}],
+ ['bundle_freetype==1', {
+ 'include_dirs': [
+ 'third_party/freetype/include',
+ ],
+ 'defines' : [
+ 'FT2_BUILD_LIBRARY',
+ ],
+ }, {
+ 'include_dirs' : [
+ '/usr/include/freetype2',
+ ],
+ }],
['OS=="linux"', {
'conditions': [
['target_arch=="x64"', {
@@ -38,7 +54,6 @@
'type': 'static_library',
'dependencies': [
'third_party/third_party.gyp:bigint',
- 'third_party/third_party.gyp:freetype',
'third_party/third_party.gyp:safemath',
'fdrm',
'fpdfdoc',
@@ -102,6 +117,17 @@
'fpdfsdk/src/fpdfsdkdll.rc',
],
}],
+ ['bundle_freetype==1', {
+ 'dependencies': [
+ 'third_party/third_party.gyp:freetype',
+ ],
+ }, {
+ 'link_settings': {
+ 'libraries': [
+ '-lfreetype',
+ ],
+ },
+ }],
],
'all_dependent_settings': {
'msvs_settings': {