GlyphContext - Lazy glyph-char-mapping
This commit is contained in:
1 parent
1263b91cfd
commit
340c270e8a
1 file changed
+7
-7
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
@@ -12,8 +13,8 @@ namespace mbts.ui.utility.text {
|
||||
/// </summary>
|
||||
class GlyphContext {
|
||||
static readonly GlyphTypeface _default_glyph_typeface;
|
||||
static readonly ConcurrentDictionary<GlyphTypeface, ReadOnlyDictionary<int, (ushort index, double width)>> _glyph_char_maps =
|
||||
new ConcurrentDictionary<GlyphTypeface, ReadOnlyDictionary<int, (ushort index, double width)>>();
|
||||
static readonly ConcurrentDictionary<GlyphTypeface, Lazy<ReadOnlyDictionary<int, (ushort index, double width)>>> _glyph_char_maps =
|
||||
new ConcurrentDictionary<GlyphTypeface, Lazy<ReadOnlyDictionary<int, (ushort index, double width)>>>();
|
||||
|
||||
readonly GlyphTypeface _glyph_typeface;
|
||||
readonly IDictionary<int, (ushort index, double width)> _char_map;
|
||||
@@ -59,13 +60,12 @@ namespace mbts.ui.utility.text {
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
}
|
||||
|
||||
static ReadOnlyDictionary<int, (ushort index, double width)> _get_glyph_char_map(GlyphTypeface glyph_typeface) {
|
||||
return _glyph_char_maps.GetOrAdd(glyph_typeface, gt => {
|
||||
static ReadOnlyDictionary<int, (ushort index, double width)> _get_glyph_char_map(GlyphTypeface glyph_typeface) =>
|
||||
_glyph_char_maps.GetOrAdd(glyph_typeface, gt => new Lazy<ReadOnlyDictionary<int, (ushort index, double width)>>(() => {
|
||||
var widths = glyph_typeface.AdvanceWidths;
|
||||
return new ReadOnlyDictionary<int, (ushort, double)>(
|
||||
glyph_typeface.CharacterToGlyphMap.ToDictionary(kv => kv.Key, kv => (kv.Value, widths[kv.Value])));
|
||||
});
|
||||
}
|
||||
})).Value;
|
||||
|
||||
static Point _calculate_glyph_run_origin(
|
||||
double font_size, double available_width, double available_height, double glyph_width,
|
||||
|
||||
Reference in new issue
Block a user