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.
@@ -43,10 +44,14 @@ class FreeTextEditor extends AnnotationEditor {
43
44
44
45
static _internalPadding = 0 ;
45
46
47
+ static _defaultFontSize = 10 ;
48
+
49
+ static _defaultColor = "CanvasText" ;
50
+
46
51
constructor ( params ) {
47
52
super ( { ...params , name : "freeTextEditor" } ) ;
48
- this . #color = params . color || "CanvasText" ;
49
- this . #fontSize = params . fontSize || 10 ;
53
+ this . #color = params . color || FreeTextEditor . _defaultColor ;
54
+ this . #fontSize = params . fontSize || FreeTextEditor . _defaultFontSize ;
50
55
}
51
56
52
57
static initialize ( l10n ) {
@@ -90,6 +95,64 @@ class FreeTextEditor extends AnnotationEditor {
90
95
return editor ;
91
96
}
92
97
98
+ static updateDefaultParams ( type , value ) {
99
+ switch ( type ) {
100
+ case AnnotationEditorParamsType . FREETEXT_SIZE :
101
+ FreeTextEditor . _defaultFontSize = value ;
102
+ break ;
103
+ case AnnotationEditorParamsType . FREETEXT_COLOR :
104
+ FreeTextEditor . _defaultColor = value ;
105
+ break ;
106
+ }
107
+ }
108
+
109
+ /** @inheritdoc */
110
+ updateParams ( type , value ) {
111
+ switch ( type ) {
112
+ case AnnotationEditorParamsType . FREETEXT_SIZE :
113
+ this . #updateFontSize( value ) ;
114
+ break ;
115
+ case AnnotationEditorParamsType . FREETEXT_COLOR :
116
+ this . #updateColor( value ) ;
117
+ break ;
118
+ }
119
+ }
120
+
121
+ static getDefaultPropertiesToUpdate ( ) {
122
+ return [
123
+ [
124
+ AnnotationEditorParamsType . FREETEXT_SIZE ,
125
+ FreeTextEditor . _defaultFontSize ,
126
+ ] ,
127
+ [ AnnotationEditorParamsType . FREETEXT_COLOR , FreeTextEditor . _defaultColor ] ,
128
+ ] ;
129
+ }
130
+
131
+ /** @inheritdoc */
132
+ getPropertiesToUpdate ( ) {
133
+ return [
134
+ [ AnnotationEditorParamsType . FREETEXT_SIZE , this . #fontSize] ,
135
+ [ AnnotationEditorParamsType . FREETEXT_COLOR , this . #color] ,
136
+ ] ;
137
+ }
138
+
139
+ #updateFontSize( size ) {
140
+ const diff = size - this . #fontSize;
141
+ this . #fontSize = size ;
142
+ this . editorDiv . style . fontSize = `calc(${
143
+ this . #fontSize
144
+ } px * var(--zoom-factor))`;
145
+
146
+ // We must translate this editor in order to keep the base line at
147
+ // the same position.
148
+ this . translate ( 0 , - diff * this . parent . zoomFactor ) ;
149
+ }
150
+
151
+ #updateColor( color ) {
152
+ this . #color = color ;
153
+ this . editorDiv . style . color = color ;
154
+ }
155
+
93
156
/** @inheritdoc */
94
157
getInitialTranslation ( ) {
95
158
// The start of the base line is where the user clicked.
@@ -256,7 +319,7 @@ class FreeTextEditor extends AnnotationEditor {
256
319
) ;
257
320
return {
258
321
annotationType : AnnotationEditorType . FREETEXT ,
259
- color : [ 0 , 0 , 0 ] ,
322
+ color : getRGB ( this . #color ) ,
260
323
fontSize : this . #fontSize / PixelsPerInch . PDF_TO_CSS_UNITS ,
261
324
value : this . #content,
262
325
pageIndex : this . parent . pageIndex ,
0 commit comments