Export project PDFs through route-D when selected
This commit is contained in:
1 parent
21cc743236
commit
c3277531d3
4 files changed
+25
-2
No files matched your search
@@ -577,6 +577,6 @@ It accepts blank-line-separated source with a small `\section`/`\textbf`/`\emph`
|
|||||||
builder, and returns the v1-compatible preview shape plus per-page hashes and
|
builder, and returns the v1-compatible preview shape plus per-page hashes and
|
||||||
SVG. Route-D paragraphs are laid out with CMR10 advances, kerns and ligatures; runs of two or three hyphens become en/em dashes, and the PDF `/W` array reports the same advances, so extracted text keeps word boundaries. `Document::insertion_classes` caps each insertion class to a page fraction and defers overflow to the next page. The v1 `/preview` and project APIs are unchanged and remain the default.
|
SVG. Route-D paragraphs are laid out with CMR10 advances, kerns and ligatures; runs of two or three hyphens become en/em dashes, and the PDF `/W` array reports the same advances, so extracted text keeps word boundaries. `Document::insertion_classes` caps each insertion class to a page fraction and defers overflow to the next page. The v1 `/preview` and project APIs are unchanged and remain the default.
|
||||||
|
|
||||||
Project previews can opt into the new core with `POST /api/projects/{id}/preview?engine=route-d`; the same project preview without the query keeps the v1 pipeline. The web client exposes this as the `引擎: v1` / `引擎: Route-D` toggle in the preview toolbar; the choice is stored in `localStorage` and only the preview request, not the exported v1 PDF, switches engines. Route-D project previews keep a session, so an unchanged source reports zero recomputed pages and a one-paragraph edit returns the changed/recomputed page set. `POST /api/route-d/edit/{unit}` applies one paragraph edit to the last route-D
|
Project previews can opt into the new core with `POST /api/projects/{id}/preview?engine=route-d`; the same project preview without the query keeps the v1 pipeline. The web client exposes this as the `引擎: v1` / `引擎: Route-D` toggle in the preview toolbar; the choice is stored in `localStorage` and switches both the preview request and `POST /api/projects/{id}/pdf`, since the PDF handler honors the same `engine=route-d` query. Route-D project previews keep a session, so an unchanged source reports zero recomputed pages and a one-paragraph edit returns the changed/recomputed page set. `POST /api/route-d/edit/{unit}` applies one paragraph edit to the last route-D
|
||||||
document and returns the same page list plus `changedPages` and
|
document and returns the same page list plus `changedPages` and
|
||||||
`recomputedPages`, exposing the checkpoint/page-hash diff from the core.
|
`recomputedPages`, exposing the checkpoint/page-hash diff from the core.
|
||||||
@@ -520,6 +520,12 @@ fn handle_project_request(
|
|||||||
Ok(source) => source,
|
Ok(source) => source,
|
||||||
Err(error) => return respond_api_error(request, 422, &error),
|
Err(error) => return respond_api_error(request, 422, &error),
|
||||||
};
|
};
|
||||||
|
if query_param(url, "engine").as_deref() == Some("route-d") {
|
||||||
|
return match route_d::pdf_bytes(&source) {
|
||||||
|
Ok(pdf) => respond_pdf(request, pdf),
|
||||||
|
Err(error) => respond(request, 422, "text/plain; charset=utf-8", &error),
|
||||||
|
};
|
||||||
|
}
|
||||||
match compiler.compile(&source, &file_name) {
|
match compiler.compile(&source, &file_name) {
|
||||||
Ok(pdf) => respond_pdf(request, pdf),
|
Ok(pdf) => respond_pdf(request, pdf),
|
||||||
Err(error) => respond(request, 422, "text/plain; charset=utf-8", &error),
|
Err(error) => respond(request, 422, "text/plain; charset=utf-8", &error),
|
||||||
|
|||||||
+1
-1
@@ -124,7 +124,7 @@ pub fn preview_json(source: &str) -> Result<String, String> {
|
|||||||
|
|
||||||
/// Render the same checkpointed document as a route-D PDF.
|
/// Render the same checkpointed document as a route-D PDF.
|
||||||
pub fn pdf_bytes(source: &str) -> Result<Vec<u8>, String> {
|
pub fn pdf_bytes(source: &str) -> Result<Vec<u8>, String> {
|
||||||
let paragraphs = paragraphs(source)?;
|
let paragraphs = paragraphs(latex_body(source))?;
|
||||||
let document = build_document(¶graphs);
|
let document = build_document(¶graphs);
|
||||||
let engine = Engine::layout(&document);
|
let engine = Engine::layout(&document);
|
||||||
let pages: Vec<_> = engine
|
let pages: Vec<_> = engine
|
||||||
|
|||||||
@@ -260,6 +260,23 @@ fn serves_project_api_preview_and_pdf() {
|
|||||||
let pdf = server.request("POST", "/api/projects/hello/pdf", &[], "application/pdf");
|
let pdf = server.request("POST", "/api/projects/hello/pdf", &[], "application/pdf");
|
||||||
assert_eq!(pdf.status, 200, "{}", String::from_utf8_lossy(&pdf.body));
|
assert_eq!(pdf.status, 200, "{}", String::from_utf8_lossy(&pdf.body));
|
||||||
assert!(pdf.body.starts_with(b"%PDF-"), "missing PDF header");
|
assert!(pdf.body.starts_with(b"%PDF-"), "missing PDF header");
|
||||||
|
|
||||||
|
let route_d_pdf = server.request(
|
||||||
|
"POST",
|
||||||
|
"/api/projects/hello/pdf?engine=route-d",
|
||||||
|
&[],
|
||||||
|
"application/pdf",
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
route_d_pdf.status,
|
||||||
|
200,
|
||||||
|
"{}",
|
||||||
|
String::from_utf8_lossy(&route_d_pdf.body)
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
route_d_pdf.body.starts_with(b"%PDF-"),
|
||||||
|
"missing route-D PDF header"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in new issue
Block a user