#include "printing/common/metafile_utils.h"
#include <string_view>
#include <variant>
#include "base/check.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "printing/buildflags/buildflags.h"
#include "printing/mojom/print.mojom.h"
#include "skia/ext/font_utils.h"
#include "third_party/skia/include/codec/SkPngDecoder.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkFontMgr.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkPicture.h"
#include "third_party/skia/include/core/SkPictureRecorder.h"
#include "third_party/skia/include/core/SkStream.h"
#include "third_party/skia/include/core/SkString.h"
#include "third_party/skia/include/core/SkTypeface.h"
#include "third_party/skia/include/docs/SkPDFDocument.h"
#include "third_party/skia/include/encode/SkPngEncoder.h"
#include "third_party/skia/include/private/chromium/SkImageChromium.h"
#include "ui/accessibility/ax_node.h"
#include "ui/accessibility/ax_role_properties.h"
#include "ui/accessibility/ax_tree.h"
#include "ui/accessibility/ax_tree_update.h"
#if BUILDFLAG(IS_WIN)
#include "base/win/wincrypt_shim.h"
#include <XpsObjectModel.h>
#include <objbase.h>
#include "third_party/skia/include/docs/SkXPSDocument.h"
#endif
namespace {
const char kPDFStructureTypeDocument[] = …;
const char kPDFStructureTypeParagraph[] = …;
const char kPDFStructureTypeDiv[] = …;
const char kPDFStructureTypeHeading[] = …;
const char kPDFStructureTypeLink[] = …;
const char kPDFStructureTypeList[] = …;
const char kPDFStructureTypeListItemLabel[] = …;
const char kPDFStructureTypeListItemBody[] = …;
const char kPDFStructureTypeTable[] = …;
const char kPDFStructureTypeTableRow[] = …;
const char kPDFStructureTypeTableHeader[] = …;
const char kPDFStructureTypeTableCell[] = …;
const char kPDFStructureTypeFigure[] = …;
const char kPDFStructureTypeNonStruct[] = …;
const char kPDFTableAttributeOwner[] = …;
const char kPDFTableCellColSpanAttribute[] = …;
const char kPDFTableCellHeadersAttribute[] = …;
const char kPDFTableCellRowSpanAttribute[] = …;
const char kPDFTableHeaderScopeAttribute[] = …;
const char kPDFTableHeaderScopeColumn[] = …;
const char kPDFTableHeaderScopeRow[] = …;
SkString GetHeadingStructureType(int heading_level) { … }
SkPDF::DateTime TimeToSkTime(base::Time time) { … }
sk_sp<SkPicture> GetEmptyPicture() { … }
bool RecursiveBuildStructureTree(const ui::AXNode* ax_node,
SkPDF::StructureElementNode* tag) { … }
}
namespace printing {
sk_sp<SkDocument> MakePdfDocument(
std::string_view creator,
std::string_view title,
const ui::AXTreeUpdate& accessibility_tree,
mojom::GenerateDocumentOutline generate_document_outline,
SkWStream* stream) { … }
#if BUILDFLAG(IS_WIN)
sk_sp<SkDocument> MakeXpsDocument(SkWStream* stream) {
IXpsOMObjectFactory* factory = nullptr;
HRESULT hr = CoCreateInstance(CLSID_XpsOMObjectFactory, nullptr,
CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&factory));
if (FAILED(hr) || !factory) {
DLOG(ERROR) << "Unable to create XPS object factory: "
<< logging::SystemErrorCodeToString(hr);
return nullptr;
}
return SkXPS::MakeDocument(stream, factory);
}
#endif
sk_sp<SkData> SerializeOopPicture(SkPicture* pic, void* ctx) { … }
sk_sp<SkPicture> DeserializeOopPicture(const void* data,
size_t length,
void* ctx) { … }
sk_sp<SkData> SerializeOopTypeface(SkTypeface* typeface, void* ctx) { … }
sk_sp<SkTypeface> DeserializeOopTypeface(const void* data,
size_t length,
void* ctx) { … }
sk_sp<SkData> SerializeRasterImage(SkImage* img, void*) { … }
sk_sp<SkImage> DeserializeRasterImage(const void* bytes, size_t length, void*) { … }
SkSerialProcs SerializationProcs(PictureSerializationContext* picture_ctx,
TypefaceSerializationContext* typeface_ctx) { … }
SkDeserialProcs DeserializationProcs(
PictureDeserializationContext* picture_ctx,
TypefaceDeserializationContext* typeface_ctx) { … }
}