Skip to content

Commit

Permalink
impl freetext line ending style and doc
Browse files Browse the repository at this point in the history
  • Loading branch information
highkite committed Mar 25, 2021
1 parent f4c8f9b commit acd9970
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 16 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,18 @@ Creates a free text annotations. It puts a label at an arbitrary position. Notic
| textJustification | enum | (Optional) Justification of the text. {TextJustification.Left, TextJustification.Centered, TextJustification.Right}. Defaults to 'Left' |
| freetextType | enum | (Optional) Type of the freetext annotation. {FreeTextType.FreeText, FreeTextType.FreeTextCallout, FreeTextType.TypeWriter}. Defaults to FreeText. Note that the options are **not** available in most PDF viewers. A callout type annotation adds a pointer to an annotation. The TypeWriter type allows the user to insert data into the annotation, as a text box. See the image below for an example of the callout annotation. |
| calloutLine | number array | (Optional) Max four numbers representing pivot points of the callout line. This option only applies in case the callout type is selected. |
| lineEndingStyle | enum | (Optional) Type of the line ending of the callout pointer. \{LineEndingStyle.Square, LineEndingStyle.Circle, LineEndingStyle.Diamond, LineEndingStyle.OpenArrow, LineEndingStyile.ClosedArrow, LineEndingStyle.None, LineEndingStyle.Butt, LineEndingStyle.ROpenArrow, LineEndingStyle.RClosedArrow, LineEndingStyle.Slash\}. See images below for more information. |

Example of a callout annotation:

![ Example of a callout annotation](./documentation/example_free_text_callout.PNG "Example of a callout annotation")

Line ending styles of callout pointers:

| ![Square](./documentation/callout_square.PNG "Square") | ![Circle](./documentation/callout_circle.PNG "Circle") | ![Diamond](./documentation/callout_diamond.PNG "Diamond") | ![OpenArrow](./documentation/callout_open_arrow.PNG "Open arrow") | ![ClosedArrow](./documentation/callout_closed_arrow.PNG "ClosedArrow") | ![Butt](./documentation/callout_butt.PNG "Butt") | ![ROpenArrow](./documentation/callout_r_open_arrow.PNG "ROpenArrow") | ![RClosedArrow](./documentation/callout_r_closed_arrow.PNG "RClosedArrow") | ![Slash](./documentation/callout_slash.PNG "Slash") |
|---------------------------------------------------------|--------------------------------------------------------|------------------------------------------------------------|--------------------------------------------------------------------|------------------------------------------------------------------------|--------------------------------------------------|----------------------------------------------------------------------|----------------------------------------------------------------------------|-----------------------------------------------------|
| Square | Circle | Diamond | OpenArrow | ClosedArrow | Butt | ROpenArrow | RClosedArrow | Slash |

### <a name="createline"></a>createLineAnnotation(...)
Not yet implemented.

Expand Down
55 changes: 41 additions & 14 deletions _bundles/pdfAnnotate.js

Large diffs are not rendered by default.

Binary file added documentation/callout_butt.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/callout_circle.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/callout_closed_arrow.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/callout_diamond.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/callout_open_arrow.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/callout_r_closed_arrow.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/callout_r_open_arrow.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/callout_slash.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/callout_square.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,9 @@
lineEndingStyle = pdfAnnotate.LineEndingStyle.Butt
} else if (radios[7].checked) {
lineEndingStyle = pdfAnnotate.LineEndingStyle.ROpenArrow
} else if (radios[8].checked) {Ä
} else if (radios[8].checked) {
lineEndingStyle = pdfAnnotate.LineEndingStyle.RClosedArrow
} else if (radios[9].checked) {Ä
} else if (radios[9].checked) {
lineEndingStyle = pdfAnnotate.LineEndingStyle.Slash
}

Expand Down
33 changes: 33 additions & 0 deletions src/annotations/freetext_annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,32 @@ export class FreeTextAnnotationObj extends MarkupAnnotationObj implements FreeTe
this.type_encoded = [47, 70, 114, 101, 101, 84, 101, 120, 116] // = '/FreeText'
}

private convertLineEndingStyle(lne : LineEndingStyle) : number[] {
switch(lne) {
case LineEndingStyle.Square:
return Util.convertStringToAscii("/Square")
case LineEndingStyle.Circle:
return Util.convertStringToAscii("/Circle")
case LineEndingStyle.Diamond:
return Util.convertStringToAscii("/Diamond")
case LineEndingStyle.OpenArrow:
return Util.convertStringToAscii("/OpenArrow")
case LineEndingStyle.ClosedArrow:
return Util.convertStringToAscii("/ClosedArrow")
case LineEndingStyle.Butt:
return Util.convertStringToAscii("/Butt")
case LineEndingStyle.ROpenArrow:
return Util.convertStringToAscii("/ROpenArrow")
case LineEndingStyle.RClosedArrow:
return Util.convertStringToAscii("/RClosedArrow")
case LineEndingStyle.Slash:
return Util.convertStringToAscii("/Slash")
default:
return Util.convertStringToAscii("/None")
}

}

private convertJustification(just : TextJustification) : number {
switch (just) {
case TextJustification.Left:
Expand Down Expand Up @@ -96,6 +122,13 @@ export class FreeTextAnnotationObj extends MarkupAnnotationObj implements FreeTe
ret.push(WriterUtil.SPACE)
}

if (this.lineEndingStyle !== LineEndingStyle.None) {
ret = ret.concat(WriterUtil.LINE_ENDING)
ret.push(WriterUtil.SPACE)
ret = ret.concat(this.convertLineEndingStyle(this.lineEndingStyle))
ret.push(WriterUtil.SPACE)
}

return ret
}

Expand Down
1 change: 1 addition & 0 deletions src/writer-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class WriterUtil {

public static TEXT_JUSTIFICATION : number[] = [47, 81] // = '/Q'
public static IT : number[] = [47, 73, 84] // = '/IT'
public static LINE_ENDING : number[] = [47, 76, 69] // = '/LE'
public static CALLOUT_LINE : number[] = [47, 67, 76] // = '/CL'
public static QUADPOINTS: number[] = [47, 81, 117, 97, 100, 80, 111, 105, 110, 116, 115] // = '/QuadPoints'
public static VERTICES: number[] = [47, 86, 101, 114, 116, 105, 99, 101, 115] // = '/Vertices'
Expand Down

0 comments on commit acd9970

Please sign in to comment.