1// Copyright 2018 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5module blink.mojom;
6
7import "mojo/public/mojom/base/file_path.mojom";
8import "mojo/public/mojom/base/read_only_file.mojom";
9import "mojo/public/mojom/base/shared_memory.mojom";
10import "mojo/public/mojom/base/string16.mojom";
11
12struct DWriteStringPair {
13  mojo_base.mojom.String16 first;
14  mojo_base.mojom.String16 second;
15};
16
17struct DWriteFontStyle {
18  uint16 font_weight;
19  uint8 font_slant;
20  uint8 font_stretch;
21};
22
23struct FallbackFamilyAndStyle {
24  string fallback_family_name;
25  uint16 weight;
26  uint8 width;
27  uint8 slant;
28};
29
30struct MapCharactersResult {
31  uint32 family_index;
32  mojo_base.mojom.String16 family_name;
33  uint32 mapped_length;
34  float scale;
35  DWriteFontStyle font_style;
36};
37
38enum UniqueFontLookupMode {
39    kRetrieveTable,
40    kSingleLookups
41};
42
43interface DWriteFontProxy {
44  // Locates the index of the specified font family within the system
45  // collection.
46  [Sync]
47  FindFamily(mojo_base.mojom.String16 family_name) => (uint32 out_index);
48
49  // Returns the number of font families in the system collection.
50  [Sync]
51  GetFamilyCount() => (uint32 out_count);
52
53  // Returns the list of locale and family name pairs for the font family at the
54  // specified index.
55  [Sync]
56  GetFamilyNames(uint32 family_index)
57      => (array<DWriteStringPair> out_family_names);
58
59  // Returns the list of font file paths in the system font directory that
60  // contain font data for the font family at the specified index.
61  [Sync]
62  GetFontFiles(uint32 family_index)
63     => (array<mojo_base.mojom.FilePath> file_paths,
64         array<mojo_base.mojom.ReadOnlyFile> file_handles);
65
66  // Returns which font unique name matching lookup mode is to be used on the
67  // current machine. On DirectWrite 10 and above, single lookups can be
68  // performed directly against DirectWrite API. On older DirectWrite (Windows
69  // 7-8.1), unique font lookups need to be performed against a shared memory
70  // region which contains the lookup table. Compare GetUniqueFontLookupTable()
71  // for lookup mode kRetrieveTable and MatchUniqueFont for
72  // lookup mode kSingleLookups.
73  [Sync]
74  GetUniqueFontLookupMode() => (UniqueFontLookupMode lookup_mode);
75
76  // On supported Windows versions, matches a unique PostScript or full font
77  // name against the installed fonts using DirectWrite API. Returns a file path
78  // and ttc_index from which the unique font can be instantiated.  Check which
79  // mode is supported using GetFontUniqueNameLookupMode().  Returns empty path
80  // and 0 ttc index if no font is found. Must not be called if
81  // GetUniqueFontLookupMode() returned kRetrieveTable.
82  [Sync]
83  MatchUniqueFont(mojo_base.mojom.String16 font_unique_name)
84      => (mojo_base.mojom.FilePath file_path, uint32 ttc_index);
85
86  // Synchronously returns a protobuf structured lookup list of
87  // (full_font_name|postscript_name) => (font_file + ttc_index) to the
88  // renderer process as a ReadOnlySharedMemoryRegion if it is available
89  // immediately without any blocking operations. Use FontTableMatcher to
90  // perform searches in it. If it is not available without blocking operations,
91  // sync_available is false and no shared memory region is provided.
92  [Sync]
93  GetUniqueNameLookupTableIfAvailable()
94      => (bool sync_available,
95          mojo_base.mojom.ReadOnlySharedMemoryRegion? font_lookup_table);
96
97  // Asynchronously returns a protobuf structured lookup list of
98  // (full_font_name|postscript_name) => (font_file + ttc_index) to the
99  // renderer process as a ReadOnlySharedMemoryRegion. The lookup list is built
100  // on the first renderer call to retrieving this list. Use FontTableMatcher
101  // to perform searches in it. Retrieval may take up to several seconds if the
102  // table needs rebuilding on browser side.
103  GetUniqueNameLookupTable() =>
104  (mojo_base.mojom.ReadOnlySharedMemoryRegion? font_lookup_table);
105
106  // Locates a font family that is able to render the specified text using the
107  // specified style. If successful, the family_index and family_name will
108  // indicate which family in the system font collection can render the
109  // requested text and the mapped_length will indicate how many characters can
110  // be rendered. If no font exists that can render the text, family_index will
111  // be UINT32_MAX and mapped_length will indicate how many characters cannot be
112  // rendered by any installed font.
113  [Sync]
114  MapCharacters(mojo_base.mojom.String16 text,
115                DWriteFontStyle font_style,
116                mojo_base.mojom.String16 locale_name,
117                uint32 reading_direction,
118                mojo_base.mojom.String16 base_family_name)
119      => (MapCharactersResult out);
120
121  // For a given base family name, bcp47 language tag, and codepoint to look up,
122  // return a font family name that is available on the system to display the
123  // given codepoint. This internally calls Skia's
124  // SkFontMgr_DirectWrite::matchFamilyStyleCharacter which executes
125  // IDWriteTextLayout based fallback code, which cannot be run in the renderer
126  // due triggering loading the DWrite system font collection.
127  // Use only on Windows 8.0 and earlier - otherwise better fallback API is
128  // available through using a proxies IDWriteFontFallback.
129  [Sync]
130  FallbackFamilyAndStyleForCodepoint(string base_family_name,
131                                     string bcp47_language_tag,
132                                     uint32 codepoint)
133      => (FallbackFamilyAndStyle fallback_result);
134};
135