1 | import {getArrayBuffer, ResourceType} from '../util/ajax';
|
2 |
|
3 | import parseGlyphPBF from './parse_glyph_pbf';
|
4 |
|
5 | import type {StyleGlyph} from './style_glyph';
|
6 | import type {RequestManager} from '../util/request_manager';
|
7 | import type {Callback} from '../types/callback';
|
8 |
|
9 | export default function loadGlyphRange(fontstack: string,
|
10 | range: number,
|
11 | urlTemplate: string,
|
12 | requestManager: RequestManager,
|
13 | callback: Callback<{
|
14 | [_: number]: StyleGlyph | null;
|
15 | }>) {
|
16 | const begin = range * 256;
|
17 | const end = begin + 255;
|
18 |
|
19 | const request = requestManager.transformRequest(
|
20 | urlTemplate.replace('{fontstack}', fontstack).replace('{range}', `${begin}-${end}`),
|
21 | ResourceType.Glyphs
|
22 | );
|
23 |
|
24 | getArrayBuffer(request, (err?: Error | null, data?: ArrayBuffer | null) => {
|
25 | if (err) {
|
26 | callback(err);
|
27 | } else if (data) {
|
28 | const glyphs = {};
|
29 |
|
30 | for (const glyph of parseGlyphPBF(data)) {
|
31 | glyphs[glyph.id] = glyph;
|
32 | }
|
33 |
|
34 | callback(null, glyphs);
|
35 | }
|
36 | });
|
37 | }
|