14
14
*/
15
15
16
16
import {
17
+ AnnotationEditorParamsType ,
17
18
AnnotationEditorType ,
18
19
assert ,
19
20
LINE_FACTOR ,
20
21
Util ,
21
22
} from "../../shared/util.js" ;
23
+ import { getRGB , PixelsPerInch } from "../display_utils.js" ;
22
24
import { AnnotationEditor } from "./editor.js" ;
23
25
import { bindEvents } from "./tools.js" ;
24
- import { PixelsPerInch } from "../display_utils.js" ;
25
26
26
27
/**
27
28
* Basic text editor in order to create a FreeTex annotation.
@@ -41,10 +42,14 @@ class FreeTextEditor extends AnnotationEditor {
41
42
42
43
static _internalPadding = 0 ;
43
44
45
+ static _defaultFontSize = 10 ;
46
+
47
+ static _defaultColor = "CanvasText" ;
48
+
44
49
constructor ( params ) {
45
50
super ( { ...params , name : "freeTextEditor" } ) ;
46
- this . #color = params . color || "CanvasText" ;
47
- this . #fontSize = params . fontSize || 10 ;
51
+ this . #color = params . color || FreeTextEditor . _defaultColor ;
52
+ this . #fontSize = params . fontSize || FreeTextEditor . _defaultFontSize ;
48
53
}
49
54
50
55
static initialize ( l10n ) {
@@ -88,6 +93,64 @@ class FreeTextEditor extends AnnotationEditor {
88
93
return editor ;
89
94
}
90
95
96
+ static updateDefaultParams ( type , value ) {
97
+ switch ( type ) {
98
+ case AnnotationEditorParamsType . FREETEXT_SIZE :
99
+ FreeTextEditor . _defaultFontSize = value ;
100
+ break ;
101
+ case AnnotationEditorParamsType . FREETEXT_COLOR :
102
+ FreeTextEditor . _defaultColor = value ;
103
+ break ;
104
+ }
105
+ }
106
+
107
+ /** @inheritdoc */
108
+ updateParams ( type , value ) {
109
+ switch ( type ) {
110
+ case AnnotationEditorParamsType . FREETEXT_SIZE :
111
+ this . #updateFontSize( value ) ;
112
+ break ;
113
+ case AnnotationEditorParamsType . FREETEXT_COLOR :
114
+ this . #updateColor( value ) ;
115
+ break ;
116
+ }
117
+ }
118
+
119
+ static getDefaultPropertiesToUpdate ( ) {
120
+ return [
121
+ [
122
+ AnnotationEditorParamsType . FREETEXT_SIZE ,
123
+ FreeTextEditor . _defaultFontSize ,
124
+ ] ,
125
+ [ AnnotationEditorParamsType . FREETEXT_COLOR , FreeTextEditor . _defaultColor ] ,
126
+ ] ;
127
+ }
128
+
129
+ /** @inheritdoc */
130
+ getPropertiesToUpdate ( ) {
131
+ return [
132
+ [ AnnotationEditorParamsType . FREETEXT_SIZE , this . #fontSize] ,
133
+ [ AnnotationEditorParamsType . FREETEXT_COLOR , this . #color] ,
134
+ ] ;
135
+ }
136
+
137
+ #updateFontSize( size ) {
138
+ const diff = size - this . #fontSize;
139
+ this . #fontSize = size ;
140
+ this . editorDiv . style . fontSize = `calc(${
141
+ this . #fontSize
142
+ } px * var(--zoom-factor))`;
143
+
144
+ // We must translate this editor in order to keep the base line at
145
+ // the same position.
146
+ this . translate ( 0 , - diff * this . parent . zoomFactor ) ;
147
+ }
148
+
149
+ #updateColor( color ) {
150
+ this . #color = color ;
151
+ this . editorDiv . style . color = color ;
152
+ }
153
+
91
154
/** @inheritdoc */
92
155
getInitialTranslation ( ) {
93
156
// The start of the base line is where the user clicked.
@@ -247,7 +310,7 @@ class FreeTextEditor extends AnnotationEditor {
247
310
) ;
248
311
return {
249
312
annotationType : AnnotationEditorType . FREETEXT ,
250
- color : [ 0 , 0 , 0 ] ,
313
+ color : getRGB ( this . #color ) ,
251
314
fontSize : this . #fontSize / PixelsPerInch . PDF_TO_CSS_UNITS ,
252
315
value : this . #content,
253
316
pageIndex : this . parent . pageIndex ,
0 commit comments