Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PDFAnnotation intent property. #66

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/mupdf-wasm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ interface Libmupdf {
_wasm_pdf_set_annot_hidden_for_editing(annot: Pointer, v: boolean): void,
_wasm_pdf_annot_icon_name(annot: Pointer): Pointer,
_wasm_pdf_set_annot_icon_name(annot: Pointer, v: Pointer): void,
_wasm_pdf_annot_intent(annot: Pointer): number,
_wasm_pdf_set_annot_intent(annot: Pointer, v: number): void,
_wasm_pdf_annot_rect(annot: Pointer): Pointer,
_wasm_pdf_annot_popup(annot: Pointer): Pointer,
_wasm_pdf_annot_quad_point_count(annot: Pointer): number,
Expand Down
1 change: 1 addition & 0 deletions src/mupdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,7 @@ PDF_ANNOT_GETSET(int, INTEGER, quadding)
PDF_ANNOT_GETSET(boolean, BOOLEAN, is_open)
PDF_ANNOT_GETSET(boolean, BOOLEAN, hidden_for_editing)
PDF_ANNOT_GETSET(char*, POINTER, icon_name)
PDF_ANNOT_GETSET(int, INTEGER, intent)

PDF_ANNOT_GET(fz_rect*, RECT, rect)
PDF_ANNOT_GET(fz_rect*, RECT, popup)
Expand Down
34 changes: 34 additions & 0 deletions src/mupdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2724,6 +2724,18 @@ type PDFAnnotationBorderStyle = "Solid" | "Dashed" | "Beveled" | "Inset" | "Unde

type PDFAnnotationBorderEffect = "None" | "Cloudy"

type PDFAnnotationIntent =
null |
"FreeTextCallout" |
"FreeTextTypeWriter" |
"LineArrow" |
"LineDimension" |
"PloyLine" |
"PolygonCloud" |
"PolygonDimension" |
"StampImage" |
"StampSnapshot"

export class PDFAnnotation extends Userdata {
static override readonly _drop = libmupdf._wasm_pdf_drop_annot

Expand Down Expand Up @@ -2778,6 +2790,19 @@ export class PDFAnnotation extends Userdata {

static readonly BORDER_EFFECT: PDFAnnotationBorderEffect[] = [ "None", "Cloudy" ]

static readonly INTENT: PDFAnnotationIntent[] = [
null,
"FreeTextCallout",
"FreeTextTypeWriter",
"LineArrow",
"LineDimension",
"PloyLine",
"PolygonCloud",
"PolygonDimension",
"StampImage",
"StampSnapshot"
]

// Bit masks for getFlags and setFlags
static readonly IS_INVISIBLE = 1 << (1 - 1)
static readonly IS_HIDDEN = 1 << (2 - 1)
Expand Down Expand Up @@ -3100,6 +3125,15 @@ export class PDFAnnotation extends Userdata {
this.addBorderDashItem(v)
}

getIntent(): PDFAnnotationIntent {
return PDFAnnotation.INTENT[libmupdf._wasm_pdf_annot_intent(this.pointer)] || null
}

setIntent(value: PDFAnnotationIntent) {
let value_ix = ENUM<PDFAnnotationIntent>(value, PDFAnnotation.INTENT)
return libmupdf._wasm_pdf_set_annot_intent(this.pointer, value_ix)
}

setDefaultAppearance(fontName: string, size: number, color: Color) {
checkType(fontName, "string")
checkType(size, "number")
Expand Down
Loading