Skip to content

Commit

Permalink
Make the pdf build target a component.
Browse files Browse the repository at this point in the history
The code in pdf/ can be a GN component instead of a static_library.
Add a PDF_EXPORT macro and set boundaries on what can be used from
external callers.

Change-Id: Ib855736f145c5708b8c62c7fd0e3622827bcc623
Reviewed-on: https://chromium-review.googlesource.com/879853
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#531314}
  • Loading branch information
leizleiz authored and Commit Bot committed Jan 23, 2018
1 parent c70a2f8 commit ea3b54d
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 46 deletions.
13 changes: 11 additions & 2 deletions pdf/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ buildflag_header("features") {
if (enable_pdf) {
pdf_engine = 0 # 0 PDFium

static_library("pdf") {
component("pdf") {
deps = [
"//base",
"//base:i18n",
"//gin",
"//net",
"//ppapi/cpp:objects",
Expand All @@ -28,6 +29,10 @@ if (enable_pdf) {
"//ui/gfx/range",
]

public = [
"pdf.h",
]

sources = [
"chunk_stream.h",
"document_loader.cc",
Expand All @@ -44,6 +49,7 @@ if (enable_pdf) {
"pdf.h",
"pdf_engine.cc",
"pdf_engine.h",
"pdf_export.h",
"preview_mode_client.cc",
"preview_mode_client.h",
"range_set.cc",
Expand Down Expand Up @@ -79,7 +85,10 @@ if (enable_pdf) {
]
}

defines = [ "PDFIUM_PRINT_TEXT_WITH_GDI" ]
defines = [
"PDF_IMPLEMENTATION",
"PDFIUM_PRINT_TEXT_WITH_GDI",
]
if (pdf_enable_xfa) {
defines += [ "PDF_ENABLE_XFA" ]
}
Expand Down
5 changes: 3 additions & 2 deletions pdf/document_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@
#include <vector>

#include "pdf/chunk_stream.h"
#include "pdf/pdf_export.h"
#include "ppapi/utility/completion_callback_factory.h"

namespace chrome_pdf {

class URLLoaderWrapper;

class DocumentLoader {
class PDF_EXPORT DocumentLoader {
public:
// Number was chosen in crbug.com/78264#c8
static constexpr uint32_t kDefaultRequestSize = 65536;

class Client {
class PDF_EXPORT Client {
public:
virtual ~Client();

Expand Down
80 changes: 41 additions & 39 deletions pdf/pdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef PDF_PDF_H_
#define PDF_PDF_H_

#include "build/build_config.h"
#include "pdf/pdf_export.h"
#include "ppapi/c/ppb.h"
#include "ppapi/cpp/module.h"

Expand All @@ -30,10 +32,10 @@ class PDFModule : public pp::Module {
pp::Instance* CreateInstance(PP_Instance instance) override;
};

int PPP_InitializeModule(PP_Module module_id,
PPB_GetInterface get_browser_interface);
void PPP_ShutdownModule();
const void* PPP_GetInterface(const char* interface_name);
PDF_EXPORT int PPP_InitializeModule(PP_Module module_id,
PPB_GetInterface get_browser_interface);
PDF_EXPORT void PPP_ShutdownModule();
PDF_EXPORT const void* PPP_GetInterface(const char* interface_name);

#if defined(OS_WIN)
// Printing modes - type to convert PDF to for printing
Expand Down Expand Up @@ -71,35 +73,35 @@ enum PrintingMode {
// |autorotate| specifies whether the final image should be rotated to match
// the output bound.
// Returns false if the document or the page number are not valid.
bool RenderPDFPageToDC(const void* pdf_buffer,
int buffer_size,
int page_number,
HDC dc,
int dpi,
int bounds_origin_x,
int bounds_origin_y,
int bounds_width,
int bounds_height,
bool fit_to_bounds,
bool stretch_to_bounds,
bool keep_aspect_ratio,
bool center_in_bounds,
bool autorotate);

void SetPDFEnsureTypefaceCharactersAccessible(
PDF_EXPORT bool RenderPDFPageToDC(const void* pdf_buffer,
int buffer_size,
int page_number,
HDC dc,
int dpi,
int bounds_origin_x,
int bounds_origin_y,
int bounds_width,
int bounds_height,
bool fit_to_bounds,
bool stretch_to_bounds,
bool keep_aspect_ratio,
bool center_in_bounds,
bool autorotate);

PDF_EXPORT void SetPDFEnsureTypefaceCharactersAccessible(
PDFEnsureTypefaceCharactersAccessible func);

void SetPDFUseGDIPrinting(bool enable);
PDF_EXPORT void SetPDFUseGDIPrinting(bool enable);

void SetPDFUsePrintMode(int mode);
PDF_EXPORT void SetPDFUsePrintMode(int mode);
#endif // defined(OS_WIN)

// |page_count| and |max_page_width| are optional and can be NULL.
// Returns false if the document is not valid.
bool GetPDFDocInfo(const void* pdf_buffer,
int buffer_size,
int* page_count,
double* max_page_width);
PDF_EXPORT bool GetPDFDocInfo(const void* pdf_buffer,
int buffer_size,
int* page_count,
double* max_page_width);

// Gets the dimensions of a specific page in a document.
// |pdf_buffer| is the buffer that contains the entire PDF document to be
Expand All @@ -110,11 +112,11 @@ bool GetPDFDocInfo(const void* pdf_buffer,
// |width| is the output for the width of the page in points.
// |height| is the output for the height of the page in points.
// Returns false if the document or the page number are not valid.
bool GetPDFPageSizeByIndex(const void* pdf_buffer,
int pdf_buffer_size,
int page_number,
double* width,
double* height);
PDF_EXPORT bool GetPDFPageSizeByIndex(const void* pdf_buffer,
int pdf_buffer_size,
int page_number,
double* width,
double* height);

// Renders PDF page into 4-byte per pixel BGRA color bitmap.
// |pdf_buffer| is the buffer that contains the entire PDF document to be
Expand All @@ -128,14 +130,14 @@ bool GetPDFPageSizeByIndex(const void* pdf_buffer,
// |autorotate| specifies whether the final image should be rotated to match
// the output bound.
// Returns false if the document or the page number are not valid.
bool RenderPDFPageToBitmap(const void* pdf_buffer,
int pdf_buffer_size,
int page_number,
void* bitmap_buffer,
int bitmap_width,
int bitmap_height,
int dpi,
bool autorotate);
PDF_EXPORT bool RenderPDFPageToBitmap(const void* pdf_buffer,
int pdf_buffer_size,
int page_number,
void* bitmap_buffer,
int bitmap_width,
int bitmap_height,
int dpi,
bool autorotate);

} // namespace chrome_pdf

Expand Down
29 changes: 29 additions & 0 deletions pdf/pdf_export.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef PDF_PDF_EXPORT_H_
#define PDF_PDF_EXPORT_H_

#if defined(COMPONENT_BUILD)
#if defined(WIN32)

#if defined(PDF_IMPLEMENTATION)
#define PDF_EXPORT __declspec(dllexport)
#else
#define PDF_EXPORT __declspec(dllimport)
#endif // defined(PDF_IMPLEMENTATION)

#else // defined(WIN32)
#if defined(PDF_IMPLEMENTATION)
#define PDF_EXPORT __attribute__((visibility("default")))
#else
#define PDF_EXPORT
#endif
#endif

#else // defined(COMPONENT_BUILD)
#define PDF_EXPORT
#endif

#endif // PDF_PDF_EXPORT_H_
7 changes: 4 additions & 3 deletions pdf/range_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
#include <set>
#include <string>

#include "pdf/pdf_export.h"
#include "ui/gfx/range/range.h"

namespace chrome_pdf {

class RangeSet {
class PDF_EXPORT RangeSet {
public:
RangeSet();
explicit RangeSet(const gfx::Range& range);
Expand Down Expand Up @@ -71,7 +72,7 @@ class RangeSet {

} // namespace chrome_pdf

std::ostream& operator<<(std::ostream& os,
const chrome_pdf::RangeSet& range_set);
PDF_EXPORT std::ostream& operator<<(std::ostream& os,
const chrome_pdf::RangeSet& range_set);

#endif // PDF_RANGE_SET_H_

0 comments on commit ea3b54d

Please sign in to comment.