@breakside/jskit 2022.22.2 → 2022.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Frameworks/DOM.jsframework/Info.json +2 -2
- package/Frameworks/DOM.jsframework/JS/XMLSerializer.js +9 -4
- package/Frameworks/DOM.jsframework/io.breakside.JSKit.DOM-bundle.js +2 -2
- package/Frameworks/DOM.jsframework/sources.json +10 -3
- package/Frameworks/FontKit.jsframework/Info.json +2 -2
- package/Frameworks/FontKit.jsframework/io.breakside.JSKit.FontKit-bundle.js +2 -2
- package/Frameworks/FontKit.jsframework/sources.json +34 -2
- package/Frameworks/Foundation.jsframework/Info.json +2 -2
- package/Frameworks/Foundation.jsframework/JS/JSAttributedString.js +347 -25
- package/Frameworks/Foundation.jsframework/JS/JSFont.js +39 -15
- package/Frameworks/Foundation.jsframework/JS/JSFontDescriptor+HTML.js +8 -0
- package/Frameworks/Foundation.jsframework/JS/JSFontDescriptor.js +105 -27
- package/Frameworks/Foundation.jsframework/JS/JSParagraphStyle.js +71 -0
- package/Frameworks/Foundation.jsframework/JS/JSTextAttachment.js +1 -1
- package/Frameworks/Foundation.jsframework/JS/JSTextContainer.js +56 -29
- package/Frameworks/Foundation.jsframework/JS/JSTextFrame.js +2 -32
- package/Frameworks/Foundation.jsframework/JS/JSTextFramesetter.js +125 -22
- package/Frameworks/Foundation.jsframework/JS/JSTextLayoutManager.js +11 -3
- package/Frameworks/Foundation.jsframework/JS/JSTextLine.js +4 -3
- package/Frameworks/Foundation.jsframework/JS/JSTextRun.js +5 -3
- package/Frameworks/Foundation.jsframework/JS/JSTextTypesetter.js +41 -25
- package/Frameworks/Foundation.jsframework/JS/String+JS.js +69 -0
- package/Frameworks/Foundation.jsframework/JS/UnicodeChar.js +8 -0
- package/Frameworks/Foundation.jsframework/io.breakside.JSKit.Foundation-bundle.js +2 -2
- package/Frameworks/Foundation.jsframework/sources.json +170 -8
- package/Frameworks/SecurityKit.jsframework/Info.json +2 -2
- package/Frameworks/SecurityKit.jsframework/io.breakside.JSKit.SecurityKit-bundle.js +2 -2
- package/Frameworks/SecurityKit.jsframework/sources.json +43 -2
- package/Info.json +2 -2
- package/Node/Builder.js +20 -9
- package/Node/FrameworkBuilder.js +22 -2
- package/Node/Project.js +22 -2
- package/Node/io.breakside.jskit-bundle.js +2 -2
- package/Node/jskit +8 -7
- package/Root/Frameworks/APIKit/Info.yaml +1 -1
- package/Root/Frameworks/APIKitTesting/Info.yaml +1 -1
- package/Root/Frameworks/AuthKit/Info.yaml +1 -1
- package/Root/Frameworks/CSSOM/Info.yaml +1 -1
- package/Root/Frameworks/ChartKit/CHAxis.js +5 -5
- package/Root/Frameworks/ChartKit/CHPieChart.js +1 -1
- package/Root/Frameworks/ChartKit/Info.yaml +1 -1
- package/Root/Frameworks/ConferenceKit/Info.yaml +1 -1
- package/Root/Frameworks/DBKit/Info.yaml +1 -1
- package/Root/Frameworks/DOM/Info.yaml +1 -1
- package/Root/Frameworks/DOM/XMLSerializer.js +9 -4
- package/Root/Frameworks/Dispatch/Info.yaml +1 -1
- package/Root/Frameworks/FontKit/Info.yaml +1 -1
- package/Root/Frameworks/Foundation/Info.yaml +1 -1
- package/Root/Frameworks/Foundation/JSAttributedString.js +347 -25
- package/Root/Frameworks/Foundation/JSFont.js +39 -15
- package/Root/Frameworks/Foundation/JSFontDescriptor+HTML.js +8 -0
- package/Root/Frameworks/Foundation/JSFontDescriptor.js +105 -27
- package/Root/Frameworks/Foundation/JSParagraphStyle.js +71 -0
- package/Root/Frameworks/Foundation/JSTextAttachment.js +1 -1
- package/Root/Frameworks/Foundation/JSTextContainer.js +56 -29
- package/Root/Frameworks/Foundation/JSTextFrame.js +2 -32
- package/Root/Frameworks/Foundation/JSTextFramesetter.js +125 -22
- package/Root/Frameworks/Foundation/JSTextLayoutManager.js +11 -3
- package/Root/Frameworks/Foundation/JSTextLine.js +4 -3
- package/Root/Frameworks/Foundation/JSTextRun.js +5 -3
- package/Root/Frameworks/Foundation/JSTextTypesetter.js +41 -25
- package/Root/Frameworks/Foundation/String+JS.js +69 -0
- package/Root/Frameworks/Foundation/UnicodeChar.js +8 -0
- package/Root/Frameworks/ImageKit/Info.yaml +1 -1
- package/Root/Frameworks/MediaKit/Info.yaml +1 -1
- package/Root/Frameworks/MediaKitUI/Info.yaml +1 -1
- package/Root/Frameworks/NotificationKit/Info.yaml +1 -1
- package/Root/Frameworks/PDFKit/Info.yaml +1 -1
- package/Root/Frameworks/QRKit/Info.yaml +1 -1
- package/Root/Frameworks/SearchKit/Info.yaml +1 -1
- package/Root/Frameworks/SecurityKit/Info.yaml +1 -1
- package/Root/Frameworks/ServerKit/Info.yaml +1 -1
- package/Root/Frameworks/ServerKitTesting/Info.yaml +1 -1
- package/Root/Frameworks/TestKit/Info.yaml +1 -1
- package/Root/Frameworks/UIKit/Info.yaml +1 -1
- package/Root/Frameworks/UIKit/UIHTMLContentEditableTextInputManager.js +36 -0
- package/Root/Frameworks/UIKit/UIHTMLDisplayServer.js +1 -1
- package/Root/Frameworks/UIKit/UIHTMLTextField.js +1 -1
- package/Root/Frameworks/UIKit/UIHTMLTextFrame.js +19 -91
- package/Root/Frameworks/UIKit/UIHTMLTextFramesetter.js +52 -9
- package/Root/Frameworks/UIKit/UIHTMLTextLine.js +95 -30
- package/Root/Frameworks/UIKit/UIHTMLTextRun.js +22 -9
- package/Root/Frameworks/UIKit/UIHTMLTextTypesetter.js +334 -459
- package/Root/Frameworks/UIKit/UIHTMLWindowServer.js +16 -0
- package/Root/Frameworks/UIKit/UILabel.js +43 -10
- package/Root/Frameworks/UIKit/UIScrollView.js +12 -0
- package/Root/Frameworks/UIKit/UISegmentedControl.js +6 -6
- package/Root/Frameworks/UIKit/UITextAttachmentView.js +1 -1
- package/Root/Frameworks/UIKit/UITextEditor.js +210 -25
- package/Root/Frameworks/UIKit/UITextField.js +58 -31
- package/Root/Frameworks/UIKit/UITextInput.js +3 -1
- package/Root/Frameworks/UIKit/UITextInputManager.js +2 -2
- package/Root/Frameworks/UIKit/UITextLayer.js +39 -26
- package/Root/Frameworks/UIKit/UITokenField.js +4 -4
- package/Root/Frameworks/UIKit/UIView.js +3 -1
- package/Root/Frameworks/UIKit/UIWindow.js +16 -3
- package/Root/Frameworks/UIKitTesting/Info.yaml +1 -1
- package/package.json +1 -1
|
@@ -49,7 +49,7 @@ JSClass("JSFont", JSObject, {
|
|
|
49
49
|
var weight;
|
|
50
50
|
var style;
|
|
51
51
|
var size;
|
|
52
|
-
var defaults =
|
|
52
|
+
var defaults = JSFontDescriptor.system;
|
|
53
53
|
// if ('descriptor' in values){
|
|
54
54
|
// values = values.descriptor;
|
|
55
55
|
// }
|
|
@@ -78,7 +78,7 @@ JSClass("JSFont", JSObject, {
|
|
|
78
78
|
size = JSFont.Size.normal;
|
|
79
79
|
}
|
|
80
80
|
if (family){
|
|
81
|
-
var descriptor =
|
|
81
|
+
var descriptor = JSFontDescriptor.descriptorWithFamily(family, weight, style);
|
|
82
82
|
if (descriptor !== null){
|
|
83
83
|
return JSFont.initWithDescriptor(descriptor, size);
|
|
84
84
|
}
|
|
@@ -86,6 +86,30 @@ JSClass("JSFont", JSObject, {
|
|
|
86
86
|
return null;
|
|
87
87
|
},
|
|
88
88
|
|
|
89
|
+
initFromDictionary: function(dictionary){
|
|
90
|
+
var descriptor = JSFontDescriptor.descriptorWithFamily(dictionary.family, dictionary.weight, dictionary.style);
|
|
91
|
+
if (descriptor === null){
|
|
92
|
+
if (dictionary.url){
|
|
93
|
+
descriptor = JSURLFontDescriptor.initWithURL(JSURL.initWithString(dictionary.url), dictionary.family, dictionary.weight, dictionary.style);
|
|
94
|
+
JSFontDescriptor.registerDescriptor(descriptor);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (descriptor !== null){
|
|
98
|
+
return JSFont.initWithDescriptor(descriptor, dictionary.size);
|
|
99
|
+
}
|
|
100
|
+
return null;
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
dictionaryRepresentation: function(){
|
|
104
|
+
return {
|
|
105
|
+
url: this.descriptor instanceof JSURLFontDescriptor ? this._descriptor.url : undefined,
|
|
106
|
+
family: this._descriptor.family,
|
|
107
|
+
weight: this._descriptor.weight,
|
|
108
|
+
style: this._descriptor.style,
|
|
109
|
+
size: this.pointSize
|
|
110
|
+
};
|
|
111
|
+
},
|
|
112
|
+
|
|
89
113
|
getFullName: function(){
|
|
90
114
|
return this._descriptor.name;
|
|
91
115
|
},
|
|
@@ -187,7 +211,7 @@ JSClass("JSFont", JSObject, {
|
|
|
187
211
|
});
|
|
188
212
|
|
|
189
213
|
JSFont.fontWithFamily = function(family, pointSize, weight, style){
|
|
190
|
-
var descriptor =
|
|
214
|
+
var descriptor = JSFontDescriptor.descriptorWithFamily(family, weight || JSFont.Weight.regular, style || JSFont.Style.normal);
|
|
191
215
|
return JSFont.initWithDescriptor(descriptor, pointSize);
|
|
192
216
|
};
|
|
193
217
|
|
|
@@ -204,12 +228,12 @@ JSFont.registerBundleFonts = function(bundle){
|
|
|
204
228
|
|
|
205
229
|
JSFont._registerFontResource = function(bundle, metadata){
|
|
206
230
|
var descriptor = JSResourceFontDescriptor.initWithMetadata(bundle, metadata);
|
|
231
|
+
JSFontDescriptor.registerDescriptor(descriptor);
|
|
207
232
|
return descriptor;
|
|
208
233
|
};
|
|
209
234
|
|
|
210
|
-
JSFont.
|
|
211
|
-
|
|
212
|
-
JSFont.registerSystemFontResource = function(name){
|
|
235
|
+
JSFont.registerSystemFontResource = function(name, bundle){
|
|
236
|
+
bundle = bundle || JSBundle.mainBundle;
|
|
213
237
|
var ext;
|
|
214
238
|
var extIndex = name.lastIndexOf('.');
|
|
215
239
|
var i, l;
|
|
@@ -221,33 +245,33 @@ JSFont.registerSystemFontResource = function(name){
|
|
|
221
245
|
extGuessed = true;
|
|
222
246
|
ext = "ttf";
|
|
223
247
|
}
|
|
224
|
-
var metadata =
|
|
248
|
+
var metadata = bundle.metadataForResourceName(name, ext);
|
|
225
249
|
if (extGuessed && metadata === null){
|
|
226
250
|
ext = "otf";
|
|
227
|
-
metadata =
|
|
251
|
+
metadata = bundle.metadataForResourceName(name, ext);
|
|
228
252
|
}
|
|
229
|
-
|
|
253
|
+
JSFontDescriptor.system = JSResourceFontDescriptor.descriptorsByName[metadata.font.unique_identifier];
|
|
230
254
|
};
|
|
231
255
|
|
|
232
256
|
JSFont.registerSystemFont = function(familyName, weight, style){
|
|
233
|
-
|
|
257
|
+
JSFontDescriptor.system = JSFontDescriptor.descriptorWithFamily(familyName, weight || JSFont.Weight.regular, style || JSFont.Style.normal);
|
|
234
258
|
};
|
|
235
259
|
|
|
236
260
|
JSFont.registerSystemFontDescriptor = function(descriptor){
|
|
237
|
-
|
|
261
|
+
JSFontDescriptor.system = descriptor;
|
|
238
262
|
};
|
|
239
263
|
|
|
240
264
|
JSFont.unregisterAllFonts = function(){
|
|
241
|
-
|
|
265
|
+
JSFontDescriptor.descriptorsByFamily = {};
|
|
242
266
|
JSResourceFontDescriptor.descriptorsByName = {};
|
|
243
|
-
|
|
267
|
+
JSFontDescriptor.system = null;
|
|
244
268
|
};
|
|
245
269
|
|
|
246
270
|
JSFont.systemFontOfSize = function(pointSize){
|
|
247
|
-
if (
|
|
271
|
+
if (JSFontDescriptor.system === null){
|
|
248
272
|
return null;
|
|
249
273
|
}
|
|
250
|
-
return JSFont.initWithDescriptor(
|
|
274
|
+
return JSFont.initWithDescriptor(JSFontDescriptor.system, pointSize);
|
|
251
275
|
};
|
|
252
276
|
|
|
253
277
|
JSFont.Size = {
|
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
// #import "UnicodeChar.js"
|
|
19
19
|
// #import "Zlib.js"
|
|
20
20
|
// #import "CoreTypes.js"
|
|
21
|
+
// #import "JSURLSession.js"
|
|
22
|
+
/* global JSFont */
|
|
21
23
|
'use strict';
|
|
22
24
|
|
|
23
25
|
(function(){
|
|
@@ -38,11 +40,11 @@ JSClass("JSFontDescriptor", JSObject, {
|
|
|
38
40
|
unitsPerEM: JSReadOnlyProperty('_unitsPerEM', 0),
|
|
39
41
|
|
|
40
42
|
descriptorWithWeight: function(weight){
|
|
41
|
-
return this;
|
|
43
|
+
return JSFontDescriptor.descriptorWithFamily(this.family, weight, this.style) || this;
|
|
42
44
|
},
|
|
43
45
|
|
|
44
46
|
descriptorWithStyle: function(style){
|
|
45
|
-
return this;
|
|
47
|
+
return JSFontDescriptor.descriptorWithFamily(this.family, this.weight, style) || this;
|
|
46
48
|
},
|
|
47
49
|
|
|
48
50
|
glyphForCharacter: function(character){
|
|
@@ -89,6 +91,29 @@ JSClass("JSFontDescriptor", JSObject, {
|
|
|
89
91
|
|
|
90
92
|
});
|
|
91
93
|
|
|
94
|
+
JSFontDescriptor.system = null;
|
|
95
|
+
|
|
96
|
+
JSFontDescriptor.descriptorsByFamily = {
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
JSFontDescriptor.registerDescriptor = function(descriptor){
|
|
100
|
+
if (!(descriptor._family in JSFontDescriptor.descriptorsByFamily)){
|
|
101
|
+
JSFontDescriptor.descriptorsByFamily[descriptor._family] = {};
|
|
102
|
+
}
|
|
103
|
+
if (!(descriptor._weight in JSFontDescriptor.descriptorsByFamily[descriptor._family])){
|
|
104
|
+
JSFontDescriptor.descriptorsByFamily[descriptor._family][descriptor._weight] = {};
|
|
105
|
+
}
|
|
106
|
+
if (!(descriptor._style in JSFontDescriptor.descriptorsByFamily[descriptor._family][descriptor._weight])){
|
|
107
|
+
JSFontDescriptor.descriptorsByFamily[descriptor._family][descriptor._weight][descriptor._style] = descriptor;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
JSFontDescriptor.descriptorWithFamily = function(family, weight, style){
|
|
112
|
+
var weights = JSFontDescriptor.descriptorsByFamily[family] || {};
|
|
113
|
+
var styles = weights[weight] || {};
|
|
114
|
+
return styles[style] || null;
|
|
115
|
+
};
|
|
116
|
+
|
|
92
117
|
JSClass("JSDataFontDescriptor", JSFontDescriptor, {
|
|
93
118
|
|
|
94
119
|
data: null,
|
|
@@ -131,23 +156,6 @@ JSClass("JSResourceFontDescriptor", JSFontDescriptor, {
|
|
|
131
156
|
widths: null,
|
|
132
157
|
};
|
|
133
158
|
JSResourceFontDescriptor.descriptorsByName[metadata.font.unique_identifier] = this;
|
|
134
|
-
if (!(this._family in JSResourceFontDescriptor.descriptorsByFamily)){
|
|
135
|
-
JSResourceFontDescriptor.descriptorsByFamily[this._family] = {};
|
|
136
|
-
}
|
|
137
|
-
if (!(this._weight in JSResourceFontDescriptor.descriptorsByFamily[this._family])){
|
|
138
|
-
JSResourceFontDescriptor.descriptorsByFamily[this._family][this._weight] = {};
|
|
139
|
-
}
|
|
140
|
-
if (!(this._style in JSResourceFontDescriptor.descriptorsByFamily[this._family][this._weight])){
|
|
141
|
-
JSResourceFontDescriptor.descriptorsByFamily[this._family][this._weight][this._style] = this;
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
|
|
145
|
-
descriptorWithWeight: function(weight){
|
|
146
|
-
return JSResourceFontDescriptor.descriptorWithFamily(this.family, weight, this.style) || this;
|
|
147
|
-
},
|
|
148
|
-
|
|
149
|
-
descriptorWithStyle: function(style){
|
|
150
|
-
return JSResourceFontDescriptor.descriptorWithFamily(this.family, this.weight, style) || this;
|
|
151
159
|
},
|
|
152
160
|
|
|
153
161
|
glyphForCharacter: function(character){
|
|
@@ -228,17 +236,87 @@ JSClass("JSResourceFontDescriptor", JSFontDescriptor, {
|
|
|
228
236
|
|
|
229
237
|
});
|
|
230
238
|
|
|
231
|
-
JSResourceFontDescriptor.
|
|
232
|
-
var weights = JSResourceFontDescriptor.descriptorsByFamily[family] || {};
|
|
233
|
-
var styles = weights[weight] || {};
|
|
234
|
-
return styles[style];
|
|
239
|
+
JSResourceFontDescriptor.descriptorsByName = {
|
|
235
240
|
};
|
|
236
241
|
|
|
237
|
-
|
|
238
|
-
};
|
|
242
|
+
JSClass("JSURLFontDescriptor", JSFontDescriptor, {
|
|
239
243
|
|
|
240
|
-
|
|
241
|
-
|
|
244
|
+
url: null,
|
|
245
|
+
|
|
246
|
+
initWithURL: function(url, family, weight, style){
|
|
247
|
+
this.url = url;
|
|
248
|
+
this._family = family;
|
|
249
|
+
this._weight = weight;
|
|
250
|
+
this._style = style;
|
|
251
|
+
this._postScriptName = "%s-%s".sprintf(family.replace(" ", ""), this.face.replce(" ", ""));
|
|
252
|
+
// this._ascender
|
|
253
|
+
// this._descender
|
|
254
|
+
// this._unitsPerEM
|
|
255
|
+
},
|
|
256
|
+
|
|
257
|
+
getData: function(completion, target){
|
|
258
|
+
if (!completion){
|
|
259
|
+
completion = Promise.completion(Promise.rejectNonNullSecondArgument);
|
|
260
|
+
}
|
|
261
|
+
var session = JSURLSession.shared;
|
|
262
|
+
var task = session.dataTaskWithURL(this.url, function(error){
|
|
263
|
+
if (error !== null){
|
|
264
|
+
completion.call(target, null, error);
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
try{
|
|
268
|
+
task.response.assertSuccess();
|
|
269
|
+
}catch (e){
|
|
270
|
+
completion.call(target, null, e);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
completion.call(target, task.response.data, null);
|
|
274
|
+
});
|
|
275
|
+
task.resume();
|
|
276
|
+
return completion.promise;
|
|
277
|
+
},
|
|
278
|
+
|
|
279
|
+
face: JSLazyInitProperty(function(){
|
|
280
|
+
if (this.weight === JSFont.Weight.regular){
|
|
281
|
+
if (this.style === JSFont.Style.italic){
|
|
282
|
+
return "Italic";
|
|
283
|
+
}
|
|
284
|
+
return "Regular";
|
|
285
|
+
}
|
|
286
|
+
var name = "";
|
|
287
|
+
switch (this.weight){
|
|
288
|
+
case JSFont.Weight.ultraLight:
|
|
289
|
+
name = "UltraLight";
|
|
290
|
+
break;
|
|
291
|
+
case JSFont.Weight.thin:
|
|
292
|
+
name = "Thin";
|
|
293
|
+
break;
|
|
294
|
+
case JSFont.Weight.light:
|
|
295
|
+
name = "Light";
|
|
296
|
+
break;
|
|
297
|
+
case JSFont.Weight.medium:
|
|
298
|
+
name = "Medium";
|
|
299
|
+
break;
|
|
300
|
+
case JSFont.Weight.semibold:
|
|
301
|
+
name = "SemiBold";
|
|
302
|
+
break;
|
|
303
|
+
case JSFont.Weight.bold:
|
|
304
|
+
name = "Bold";
|
|
305
|
+
break;
|
|
306
|
+
case JSFont.Weight.heavy:
|
|
307
|
+
name = "Heavy";
|
|
308
|
+
break;
|
|
309
|
+
case JSFont.Weight.black:
|
|
310
|
+
name = "Black";
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
if (this.style === JSFont.Style.italic){
|
|
314
|
+
name += " Italic";
|
|
315
|
+
}
|
|
316
|
+
return name;
|
|
317
|
+
}),
|
|
318
|
+
|
|
319
|
+
});
|
|
242
320
|
|
|
243
321
|
var CMap = function(format, data){
|
|
244
322
|
if (this === undefined){
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// #import "JSObject.js"
|
|
2
|
+
// #import "CoreTypes.js"
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
JSClass("JSParagraphStyle", JSObject, {
|
|
6
|
+
|
|
7
|
+
textAlignment: JSTextAlignment.left,
|
|
8
|
+
lineBreakMode: JSLineBreakMode.truncateTail,
|
|
9
|
+
lineSpacing: 0,
|
|
10
|
+
minimumLineHeight: 0,
|
|
11
|
+
lineHeightMultiple: 0,
|
|
12
|
+
paragraphSpacing: 0,
|
|
13
|
+
beforeParagraphSpacing: 0,
|
|
14
|
+
firstLineHeadIndent: 0,
|
|
15
|
+
headIndent: 0,
|
|
16
|
+
tailIndent: 0,
|
|
17
|
+
|
|
18
|
+
init: function(){
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
styleWithAttributes: function(attributes){
|
|
22
|
+
var style = this.copy();
|
|
23
|
+
if (attributes.textAlignment !== undefined){
|
|
24
|
+
style.textAlignment = attributes.textAlignment;
|
|
25
|
+
}
|
|
26
|
+
if (attributes.lineBreakMode !== undefined){
|
|
27
|
+
style.lineBreakMode = attributes.lineBreakMode;
|
|
28
|
+
}
|
|
29
|
+
if (attributes.lineSpacing !== undefined){
|
|
30
|
+
style.lineSpacing = attributes.lineSpacing;
|
|
31
|
+
}
|
|
32
|
+
if (attributes.minimumLineHeight !== undefined){
|
|
33
|
+
style.minimumLineHeight = attributes.minimumLineHeight;
|
|
34
|
+
}
|
|
35
|
+
if (attributes.lineHeightMultiple !== undefined){
|
|
36
|
+
style.lineHeightMultiple = attributes.lineHeightMultiple;
|
|
37
|
+
}
|
|
38
|
+
if (attributes.paragraphSpacing !== undefined){
|
|
39
|
+
style.paragraphSpacing = attributes.paragraphSpacing;
|
|
40
|
+
}
|
|
41
|
+
if (attributes.beforeParagraphSpacing !== undefined){
|
|
42
|
+
style.beforeParagraphSpacing = attributes.beforeParagraphSpacing;
|
|
43
|
+
}
|
|
44
|
+
if (attributes.firstLineHeadIndent !== undefined){
|
|
45
|
+
style.firstLineHeadIndent = attributes.firstLineHeadIndent;
|
|
46
|
+
}
|
|
47
|
+
if (attributes.headIndent !== undefined){
|
|
48
|
+
style.headIndent = attributes.headIndent;
|
|
49
|
+
}
|
|
50
|
+
if (attributes.tailIndent !== undefined){
|
|
51
|
+
style.tailIndent = attributes.tailIndent;
|
|
52
|
+
}
|
|
53
|
+
return style;
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
copy: function(){
|
|
57
|
+
var style = JSParagraphStyle.init();
|
|
58
|
+
style.textAlignment = this.textAlignment;
|
|
59
|
+
style.lineBreakMode = this.lineBreakMode;
|
|
60
|
+
style.lineSpacing = this.lineSpacing;
|
|
61
|
+
style.minimumLineHeight = this.minimumLineHeight;
|
|
62
|
+
style.lineHeightMultiple = this.lineHeightMultiple;
|
|
63
|
+
style.paragraphSpacing = this.paragraphSpacing;
|
|
64
|
+
style.beforeParagraphSpacing = this.beforeParagraphSpacing;
|
|
65
|
+
style.firstLineHeadIndent = this.firstLineHeadIndent;
|
|
66
|
+
style.headIndent = this.headIndent;
|
|
67
|
+
style.tailIndent = this.tailIndent;
|
|
68
|
+
return style;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
});
|
|
@@ -32,7 +32,7 @@ JSClass("JSTextAttachment", JSObject, {
|
|
|
32
32
|
this._image = image;
|
|
33
33
|
var ratio = image.size.width / image.size.height;
|
|
34
34
|
this._size = JSSize(ratio * font.displayLineHeight, font.displayLineHeight);
|
|
35
|
-
this.baselineAdjustment = font.displayDescender;
|
|
35
|
+
this.baselineAdjustment = -font.displayDescender;
|
|
36
36
|
},
|
|
37
37
|
|
|
38
38
|
initWithImage: function(image, size){
|
|
@@ -21,37 +21,13 @@
|
|
|
21
21
|
|
|
22
22
|
(function(){
|
|
23
23
|
|
|
24
|
-
var
|
|
25
|
-
if (this === undefined){
|
|
26
|
-
return new JSTextContainerAttributeProperty();
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
JSTextContainerAttributeProperty.prototype = Object.create(JSCustomProperty.prototype);
|
|
31
|
-
|
|
32
|
-
JSTextContainerAttributeProperty.prototype.define = function(C, key, extensions){
|
|
33
|
-
Object.defineProperty(C.prototype, key, {
|
|
34
|
-
configurable: false,
|
|
35
|
-
enumerable: false,
|
|
36
|
-
set: function JSTextContainer_setAttributeProperty(value){
|
|
37
|
-
this.framesetter.attributes[key] = value;
|
|
38
|
-
this._notifyLayoutManager();
|
|
39
|
-
},
|
|
40
|
-
get: function JSTextContainer_getAttributeProperty(){
|
|
41
|
-
return this.framesetter.attributes[key];
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
};
|
|
24
|
+
var logger = JSLog("foundation", "text");
|
|
45
25
|
|
|
46
26
|
JSClass("JSTextContainer", JSObject, {
|
|
47
27
|
|
|
48
28
|
origin: JSDynamicProperty('_origin', JSPoint.Zero),
|
|
49
29
|
size: JSDynamicProperty('_size', null),
|
|
50
30
|
range: JSReadOnlyProperty(),
|
|
51
|
-
lineBreakMode: JSTextContainerAttributeProperty(),
|
|
52
|
-
textAlignment: JSTextContainerAttributeProperty(),
|
|
53
|
-
lineSpacing: JSTextContainerAttributeProperty(),
|
|
54
|
-
minimumLineHeight: JSTextContainerAttributeProperty(),
|
|
55
31
|
textLayoutManager: JSDynamicProperty('_textLayoutManager', null),
|
|
56
32
|
maximumNumberOfLines: JSDynamicProperty('_maximumNumberOfLines', 0),
|
|
57
33
|
framesetter: null,
|
|
@@ -83,10 +59,10 @@ JSClass("JSTextContainer", JSObject, {
|
|
|
83
59
|
// If we are a single line label and we have all of the string, we *may not* need to do a new layout
|
|
84
60
|
if (this._maximumNumberOfLines == 1 && this._textFrame.range.location === 0 && this._textFrame.range.length >= this._textLayoutManager.textStorage.string.length){
|
|
85
61
|
// If the new size can still fit the entire layout, then no need to do a new layout manager layout
|
|
86
|
-
if (size.width >= this._textFrame.usedSize.width && size.height >= this._textFrame.usedSize.height){
|
|
62
|
+
if (size.width < Number.MAX_VALUE && size.height < Number.MAX_VALUE && size.width >= this._textFrame.usedSize.width && size.height >= this._textFrame.usedSize.height){
|
|
87
63
|
// Text frame can do a shortcut update by trimming excess size without affecting truncation
|
|
88
64
|
shouldNotify = false;
|
|
89
|
-
this.
|
|
65
|
+
this.framesetter._resizeFrame(this._textFrame, size);
|
|
90
66
|
}
|
|
91
67
|
}
|
|
92
68
|
if (shouldNotify){
|
|
@@ -110,6 +86,7 @@ JSClass("JSTextContainer", JSObject, {
|
|
|
110
86
|
|
|
111
87
|
createTextFrame: function(attributedString, range){
|
|
112
88
|
this.framesetter.attributedString = attributedString;
|
|
89
|
+
this.framesetter.defaultParagraphStyle = this._textLayoutManager.defaultParagraphStyle;
|
|
113
90
|
this._textFrame = this.framesetter.createFrame(this.size, range, this._maximumNumberOfLines);
|
|
114
91
|
},
|
|
115
92
|
|
|
@@ -125,7 +102,7 @@ JSClass("JSTextContainer", JSObject, {
|
|
|
125
102
|
rectForCharacterAtIndex: function(index, useLineHeight){
|
|
126
103
|
var line = this.lineForCharacterAtIndex(index);
|
|
127
104
|
if (line !== null){
|
|
128
|
-
var rect = line.rectForCharacterAtIndex(index
|
|
105
|
+
var rect = line.rectForCharacterAtIndex(index);
|
|
129
106
|
if (useLineHeight){
|
|
130
107
|
rect.origin.y = line.origin.y;
|
|
131
108
|
rect.size.height = line.size.height;
|
|
@@ -167,7 +144,57 @@ JSClass("JSTextContainer", JSObject, {
|
|
|
167
144
|
if (this._textLayoutManager !== null){
|
|
168
145
|
this._textLayoutManager.setNeedsLayout();
|
|
169
146
|
}
|
|
170
|
-
}
|
|
147
|
+
},
|
|
148
|
+
|
|
149
|
+
// MARK: - Deprecated
|
|
150
|
+
|
|
151
|
+
lineBreakMode: JSDynamicProperty(),
|
|
152
|
+
|
|
153
|
+
getLineBreakMode: function(){
|
|
154
|
+
logger.warn("JSTextContainer.lineBreakMode is deprecated");
|
|
155
|
+
return this._textLayoutManager.defaultParagraphStyle.lineBreakMode;
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
setLineBreakMode: function(lineBreakMode){
|
|
159
|
+
logger.warn("JSTextContainer.lineBreakMode is deprecated");
|
|
160
|
+
this._textLayoutManager.defaultParagraphStyle = this._textLayoutManager.defaultParagraphStyle.styleWithAttributes({lineBreakMode: lineBreakMode});
|
|
161
|
+
},
|
|
162
|
+
|
|
163
|
+
textAlignment: JSDynamicProperty(),
|
|
164
|
+
|
|
165
|
+
getTextAlignment: function(){
|
|
166
|
+
logger.warn("JSTextContainer.textAlignment is deprecated");
|
|
167
|
+
return this._textLayoutManager.defaultParagraphStyle.textAlignment;
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
setTextAlignment: function(textAlignment){
|
|
171
|
+
logger.warn("JSTextContainer.textAlignment is deprecated");
|
|
172
|
+
this._textLayoutManager.defaultParagraphStyle = this._textLayoutManager.defaultParagraphStyle.styleWithAttributes({textAlignment: textAlignment});
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
lineSpacing: JSDynamicProperty(),
|
|
176
|
+
|
|
177
|
+
getLineSpacing: function(){
|
|
178
|
+
logger.warn("JSTextContainer.lineSpacing is deprecated");
|
|
179
|
+
return this._textLayoutManager.defaultParagraphStyle.lineSpacing;
|
|
180
|
+
},
|
|
181
|
+
|
|
182
|
+
setLineSpacing: function(lineSpacing){
|
|
183
|
+
logger.warn("JSTextContainer.lineSpacing is deprecated");
|
|
184
|
+
this._textLayoutManager.defaultParagraphStyle = this._textLayoutManager.defaultParagraphStyle.styleWithAttributes({lineSpacing: lineSpacing});
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
minimumLineHeight: JSDynamicProperty(),
|
|
188
|
+
|
|
189
|
+
getMinimumLineHeight: function(){
|
|
190
|
+
logger.warn("JSTextContainer.minimumLineHeight is deprecated");
|
|
191
|
+
return this._textLayoutManager.defaultParagraphStyle.minimumLineHeight;
|
|
192
|
+
},
|
|
193
|
+
|
|
194
|
+
setMinimumLineHeight: function(minimumLineHeight){
|
|
195
|
+
logger.warn("JSTextContainer.minimumLineHeight is deprecated");
|
|
196
|
+
this._textLayoutManager.defaultParagraphStyle = this._textLayoutManager.defaultParagraphStyle.styleWithAttributes({minimumLineHeight: minimumLineHeight});
|
|
197
|
+
},
|
|
171
198
|
|
|
172
199
|
});
|
|
173
200
|
|
|
@@ -25,9 +25,8 @@ JSClass("JSTextFrame", JSObject, {
|
|
|
25
25
|
usedSize: JSReadOnlyProperty('_usedSize', null),
|
|
26
26
|
range: JSReadOnlyProperty('_range', null),
|
|
27
27
|
lines: JSReadOnlyProperty('_lines', null),
|
|
28
|
-
_alignment: JSTextAlignment.left,
|
|
29
28
|
|
|
30
|
-
initWithLines: function(lines, size
|
|
29
|
+
initWithLines: function(lines, size){
|
|
31
30
|
if (lines.length > 0){
|
|
32
31
|
this._range = JSRange(lines[0].range.location, lines[lines.length - 1].range.end - lines[0].range.location);
|
|
33
32
|
}else{
|
|
@@ -52,35 +51,6 @@ JSClass("JSTextFrame", JSObject, {
|
|
|
52
51
|
if (this._size.height === 0 || this._size.height === Number.MAX_VALUE){
|
|
53
52
|
this._size.height = y;
|
|
54
53
|
}
|
|
55
|
-
this._alignment = attributes.textAlignment;
|
|
56
|
-
this._alignLines();
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
adjustSize: function(newSize){
|
|
60
|
-
if (newSize.width < this._usedSize.width || newSize.height < this._usedSize.height){
|
|
61
|
-
throw new Error("Cannot adjust text frame to smaller than its used size");
|
|
62
|
-
}
|
|
63
|
-
this._size = JSSize(newSize);
|
|
64
|
-
this._alignLines();
|
|
65
|
-
},
|
|
66
|
-
|
|
67
|
-
_alignLines: function(){
|
|
68
|
-
var i, l;
|
|
69
|
-
var line;
|
|
70
|
-
switch (this._alignment){
|
|
71
|
-
case JSTextAlignment.center:
|
|
72
|
-
for (i = 0, l = this.lines.length; i < l; ++i){
|
|
73
|
-
line = this.lines[i];
|
|
74
|
-
line.origin.x = (this._size.width - line.size.width + line.trailingWhitespaceWidth) / 2.0;
|
|
75
|
-
}
|
|
76
|
-
break;
|
|
77
|
-
case JSTextAlignment.right:
|
|
78
|
-
for (i = 0, l = this.lines.length; i < l; ++i){
|
|
79
|
-
line = this.lines[i];
|
|
80
|
-
line.origin.x = (this._size.width - line.size.width + line.trailingWhitespaceWidth);
|
|
81
|
-
}
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
54
|
},
|
|
85
55
|
|
|
86
56
|
drawInContextAtPoint: function(context, point){
|
|
@@ -107,7 +77,7 @@ JSClass("JSTextFrame", JSObject, {
|
|
|
107
77
|
while (min < max){
|
|
108
78
|
mid = Math.floor(min + (max - min) / 2);
|
|
109
79
|
line = this._lines[mid];
|
|
110
|
-
i = line.range.location
|
|
80
|
+
i = line.range.location;
|
|
111
81
|
l = line.range.length;
|
|
112
82
|
if (index < i){
|
|
113
83
|
max = mid;
|