Preliminary Bindings for Skia's PDF Backend#40
Preliminary Bindings for Skia's PDF Backend#40sgopi93 wants to merge 5 commits intoJetBrains:masterfrom
Conversation
sgopi93
commented
Oct 22, 2020
- Binding for PDF module.
- Measuring text width is exposed from the native font.
|
Thank you for submitting this PR. Font measure looks fine. About PDF bindings, I see Skija as a very thin binding around Skia, without adding extra logic or inventing new APIs. In that light your Document does too much. I would prefer if you just expose SkPDF and SkDocument APIs to the Java, and then people can build the same logic you’ve build in Document.cc, but using JVM APIs they already have (Pictures and PictureRecorders are already avaliable). I understand that it might require some effort to actually create a PDF document using Skia-provided APIs and every user of it might need to go through the same problem, and you convinently wrote the code you think everyone will need for them. This is fine, but I prefer that to be solved in an external library, and Skija to only provide necessary Skia APIs. Could you change your PR to address that? That would be awesome, and I am looking forward to merging your contributions. Thanks! |
|
I just merged your |
|
I am tested covid positive, being away from the computer. will work on this as soon as possible. |
|
OMG hope you get better soon! Wish you strong health! |
0d81228 to
591dd5c
Compare
#include "SkCanvas.h"
#include "SkRect.h"
#include "SkStream.h"
#include "include/docs/SkPDFDocument.h"
#include <cassert>
#include <iomanip>
#include <iostream>
#include <jni.h>
class Document {
public:
Document() {}
Document(sk_sp<SkDocument> document)
: document_(document) {}
SkCanvas *startPage(SkScalar wi, SkScalar he) {
return document_->beginPage(wi, he);
}
sk_sp<SkDocument> create(SkWStream *stream) {
document_ = SkPDF::MakeDocument(stream);
return document_;
}
void endPage() { document_->endPage(); }
void close() { document_->close(); }
private:
~Document() { }
SkScalar width_;
SkScalar height_;
sk_sp<SkDocument> document_;
};
extern "C" JNIEXPORT jlong JNICALL
Java_org_jetbrains_skija_pdf_Document__1nMake(JNIEnv *env, jclass jclass,
jlong wstreamPtr,
jlong metadataPtr) {
SkWStream *wstream =
reinterpret_cast<SkWStream *>(static_cast<uintptr_t>(wstreamPtr));
const SkPDF::Metadata *metadata =
reinterpret_cast<SkPDF::Metadata *>(static_cast<uintptr_t>(metadataPtr));
// auto document = new Document(nullptr);
// auto document = new Document();
// sk_sp<SkDocument> doc = document->create(wstream);
sk_sp<SkDocument> doc = SkPDF::MakeDocument(wstream, *metadata);
return reinterpret_cast<jlong>(new Document(doc));
}
extern "C" JNIEXPORT jlong JNICALL
Java_org_jetbrains_skija_pdf_Document__1nBeginPage(JNIEnv *env, jclass jclass,
jlong ptr, jfloat width,
jfloat height) {
Document *instance = reinterpret_cast<Document *>(ptr);
SkCanvas *canvas = instance->startPage(width, height);
return reinterpret_cast<jlong>(canvas);
}
extern "C" JNIEXPORT void JNICALL
Java_org_jetbrains_skija_pdf_Document__1nEndPage(JNIEnv *env, jclass jclass,
jlong ptr) {
Document *instance = reinterpret_cast<Document *>(ptr);
instance->endPage();
}
extern "C" JNIEXPORT void JNICALL
Java_org_jetbrains_skija_pdf_Document__1nClose(JNIEnv *env, jclass jclass,
jlong ptr) {
Document *instance =
reinterpret_cast<Document *>(static_cast<uintptr_t>(ptr));
instance->close();
} |
|
@Henny20 Would you mind using the code block formatting feature, and also indenting? I can't read that as-is. EDIT: Thank you for doing so |