Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

juce_win32_Fonts.cpp 22KB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. /* This is some quick-and-dirty code to extract the typeface name from a lump of TTF file data.
  18. It's needed because although win32 will happily load a TTF file from in-memory data, it won't
  19. tell you the name of the damned font that it just loaded.. and in order to actually use the font,
  20. you need to know its name!! Anyway, this awful hack seems to work for most fonts.
  21. */
  22. namespace TTFNameExtractor
  23. {
  24. struct OffsetTable
  25. {
  26. uint32 version;
  27. uint16 numTables, searchRange, entrySelector, rangeShift;
  28. };
  29. struct TableDirectory
  30. {
  31. char tag[4];
  32. uint32 checkSum, offset, length;
  33. };
  34. struct NamingTable
  35. {
  36. uint16 formatSelector;
  37. uint16 numberOfNameRecords;
  38. uint16 offsetStartOfStringStorage;
  39. };
  40. struct NameRecord
  41. {
  42. uint16 platformID, encodingID, languageID;
  43. uint16 nameID, stringLength, offsetFromStorageArea;
  44. };
  45. static String parseNameRecord (MemoryInputStream& input, const NameRecord& nameRecord,
  46. const int64 directoryOffset, const int64 offsetOfStringStorage)
  47. {
  48. String result;
  49. const int64 oldPos = input.getPosition();
  50. input.setPosition (directoryOffset + offsetOfStringStorage + ByteOrder::swapIfLittleEndian (nameRecord.offsetFromStorageArea));
  51. const int stringLength = (int) ByteOrder::swapIfLittleEndian (nameRecord.stringLength);
  52. const int platformID = ByteOrder::swapIfLittleEndian (nameRecord.platformID);
  53. if (platformID == 0 || platformID == 3)
  54. {
  55. const int numChars = stringLength / 2 + 1;
  56. HeapBlock<uint16> buffer;
  57. buffer.calloc (numChars + 1);
  58. input.read (buffer, stringLength);
  59. for (int i = 0; i < numChars; ++i)
  60. buffer[i] = ByteOrder::swapIfLittleEndian (buffer[i]);
  61. static_jassert (sizeof (CharPointer_UTF16::CharType) == sizeof (uint16));
  62. result = CharPointer_UTF16 ((CharPointer_UTF16::CharType*) buffer.getData());
  63. }
  64. else
  65. {
  66. HeapBlock<char> buffer;
  67. buffer.calloc (stringLength + 1);
  68. input.read (buffer, stringLength);
  69. result = CharPointer_UTF8 (buffer.getData());
  70. }
  71. input.setPosition (oldPos);
  72. return result;
  73. }
  74. static String parseNameTable (MemoryInputStream& input, int64 directoryOffset)
  75. {
  76. input.setPosition (directoryOffset);
  77. NamingTable namingTable = { 0 };
  78. input.read (&namingTable, sizeof (namingTable));
  79. for (int i = 0; i < (int) ByteOrder::swapIfLittleEndian (namingTable.numberOfNameRecords); ++i)
  80. {
  81. NameRecord nameRecord = { 0 };
  82. input.read (&nameRecord, sizeof (nameRecord));
  83. if (ByteOrder::swapIfLittleEndian (nameRecord.nameID) == 4)
  84. {
  85. const String result (parseNameRecord (input, nameRecord, directoryOffset,
  86. ByteOrder::swapIfLittleEndian (namingTable.offsetStartOfStringStorage)));
  87. if (result.isNotEmpty())
  88. return result;
  89. }
  90. }
  91. return String();
  92. }
  93. static String getTypefaceNameFromFile (MemoryInputStream& input)
  94. {
  95. OffsetTable offsetTable = { 0 };
  96. input.read (&offsetTable, sizeof (offsetTable));
  97. for (int i = 0; i < (int) ByteOrder::swapIfLittleEndian (offsetTable.numTables); ++i)
  98. {
  99. TableDirectory tableDirectory;
  100. zerostruct (tableDirectory);
  101. input.read (&tableDirectory, sizeof (tableDirectory));
  102. if (String (tableDirectory.tag, sizeof (tableDirectory.tag)).equalsIgnoreCase ("name"))
  103. return parseNameTable (input, ByteOrder::swapIfLittleEndian (tableDirectory.offset));
  104. }
  105. return String();
  106. }
  107. }
  108. namespace FontEnumerators
  109. {
  110. static int CALLBACK fontEnum2 (ENUMLOGFONTEXW* lpelfe, NEWTEXTMETRICEXW*, int type, LPARAM lParam)
  111. {
  112. if (lpelfe != nullptr && (type & RASTER_FONTTYPE) == 0)
  113. {
  114. const String fontName (lpelfe->elfLogFont.lfFaceName);
  115. ((StringArray*) lParam)->addIfNotAlreadyThere (fontName.removeCharacters ("@"));
  116. }
  117. return 1;
  118. }
  119. static int CALLBACK fontEnum1 (ENUMLOGFONTEXW* lpelfe, NEWTEXTMETRICEXW*, int type, LPARAM lParam)
  120. {
  121. if (lpelfe != nullptr && (type & RASTER_FONTTYPE) == 0)
  122. {
  123. LOGFONTW lf = { 0 };
  124. lf.lfWeight = FW_DONTCARE;
  125. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  126. lf.lfQuality = DEFAULT_QUALITY;
  127. lf.lfCharSet = DEFAULT_CHARSET;
  128. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  129. lf.lfPitchAndFamily = FF_DONTCARE;
  130. const String fontName (lpelfe->elfLogFont.lfFaceName);
  131. fontName.copyToUTF16 (lf.lfFaceName, sizeof (lf.lfFaceName));
  132. HDC dc = CreateCompatibleDC (0);
  133. EnumFontFamiliesEx (dc, &lf,
  134. (FONTENUMPROCW) &fontEnum2,
  135. lParam, 0);
  136. DeleteDC (dc);
  137. }
  138. return 1;
  139. }
  140. }
  141. StringArray Font::findAllTypefaceNames()
  142. {
  143. StringArray results;
  144. #if JUCE_USE_DIRECTWRITE
  145. SharedResourcePointer<Direct2DFactories> factories;
  146. if (factories->systemFonts != nullptr)
  147. {
  148. ComSmartPtr<IDWriteFontFamily> fontFamily;
  149. uint32 fontFamilyCount = 0;
  150. fontFamilyCount = factories->systemFonts->GetFontFamilyCount();
  151. for (uint32 i = 0; i < fontFamilyCount; ++i)
  152. {
  153. HRESULT hr = factories->systemFonts->GetFontFamily (i, fontFamily.resetAndGetPointerAddress());
  154. if (SUCCEEDED (hr))
  155. results.addIfNotAlreadyThere (getFontFamilyName (fontFamily));
  156. }
  157. }
  158. else
  159. #endif
  160. {
  161. HDC dc = CreateCompatibleDC (0);
  162. {
  163. LOGFONTW lf = { 0 };
  164. lf.lfWeight = FW_DONTCARE;
  165. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  166. lf.lfQuality = DEFAULT_QUALITY;
  167. lf.lfCharSet = DEFAULT_CHARSET;
  168. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  169. lf.lfPitchAndFamily = FF_DONTCARE;
  170. EnumFontFamiliesEx (dc, &lf,
  171. (FONTENUMPROCW) &FontEnumerators::fontEnum1,
  172. (LPARAM) &results, 0);
  173. }
  174. DeleteDC (dc);
  175. }
  176. results.sort (true);
  177. return results;
  178. }
  179. StringArray Font::findAllTypefaceStyles (const String& family)
  180. {
  181. if (FontStyleHelpers::isPlaceholderFamilyName (family))
  182. return findAllTypefaceStyles (FontStyleHelpers::getConcreteFamilyNameFromPlaceholder (family));
  183. StringArray results;
  184. #if JUCE_USE_DIRECTWRITE
  185. SharedResourcePointer<Direct2DFactories> factories;
  186. if (factories->systemFonts != nullptr)
  187. {
  188. BOOL fontFound = false;
  189. uint32 fontIndex = 0;
  190. HRESULT hr = factories->systemFonts->FindFamilyName (family.toWideCharPointer(), &fontIndex, &fontFound);
  191. if (! fontFound)
  192. fontIndex = 0;
  193. // Get the font family using the search results
  194. // Fonts like: Times New Roman, Times New Roman Bold, Times New Roman Italic are all in the same font family
  195. ComSmartPtr<IDWriteFontFamily> fontFamily;
  196. hr = factories->systemFonts->GetFontFamily (fontIndex, fontFamily.resetAndGetPointerAddress());
  197. // Get the font faces
  198. ComSmartPtr<IDWriteFont> dwFont;
  199. uint32 fontFacesCount = 0;
  200. fontFacesCount = fontFamily->GetFontCount();
  201. for (uint32 i = 0; i < fontFacesCount; ++i)
  202. {
  203. hr = fontFamily->GetFont (i, dwFont.resetAndGetPointerAddress());
  204. // Ignore any algorithmically generated bold and oblique styles..
  205. if (dwFont->GetSimulations() == DWRITE_FONT_SIMULATIONS_NONE)
  206. results.addIfNotAlreadyThere (getFontFaceName (dwFont));
  207. }
  208. }
  209. else
  210. #endif
  211. {
  212. results.add ("Regular");
  213. results.add ("Italic");
  214. results.add ("Bold");
  215. results.add ("Bold Italic");
  216. }
  217. return results;
  218. }
  219. extern bool juce_isRunningInWine();
  220. struct DefaultFontNames
  221. {
  222. DefaultFontNames()
  223. {
  224. if (juce_isRunningInWine())
  225. {
  226. // If we're running in Wine, then use fonts that might be available on Linux..
  227. defaultSans = "Bitstream Vera Sans";
  228. defaultSerif = "Bitstream Vera Serif";
  229. defaultFixed = "Bitstream Vera Sans Mono";
  230. }
  231. else
  232. {
  233. defaultSans = "Verdana";
  234. defaultSerif = "Times New Roman";
  235. defaultFixed = "Lucida Console";
  236. defaultFallback = "Tahoma"; // (contains plenty of unicode characters)
  237. }
  238. }
  239. String defaultSans, defaultSerif, defaultFixed, defaultFallback;
  240. };
  241. Typeface::Ptr Font::getDefaultTypefaceForFont (const Font& font)
  242. {
  243. static DefaultFontNames defaultNames;
  244. Font newFont (font);
  245. const String& faceName = font.getTypefaceName();
  246. if (faceName == getDefaultSansSerifFontName()) newFont.setTypefaceName (defaultNames.defaultSans);
  247. else if (faceName == getDefaultSerifFontName()) newFont.setTypefaceName (defaultNames.defaultSerif);
  248. else if (faceName == getDefaultMonospacedFontName()) newFont.setTypefaceName (defaultNames.defaultFixed);
  249. if (font.getTypefaceStyle() == getDefaultStyle())
  250. newFont.setTypefaceStyle ("Regular");
  251. return Typeface::createSystemTypefaceFor (newFont);
  252. }
  253. //==============================================================================
  254. class WindowsTypeface : public Typeface
  255. {
  256. public:
  257. WindowsTypeface (const Font& font)
  258. : Typeface (font.getTypefaceName(), font.getTypefaceStyle()),
  259. fontH (0), previousFontH (0),
  260. dc (CreateCompatibleDC (0)), memoryFont (0),
  261. ascent (1.0f), heightToPointsFactor (1.0f),
  262. defaultGlyph (-1)
  263. {
  264. loadFont();
  265. }
  266. WindowsTypeface (const void* data, size_t dataSize)
  267. : Typeface (String(), String()),
  268. fontH (0), previousFontH (0),
  269. dc (CreateCompatibleDC (0)), memoryFont (0),
  270. ascent (1.0f), heightToPointsFactor (1.0f),
  271. defaultGlyph (-1)
  272. {
  273. DWORD numInstalled = 0;
  274. memoryFont = AddFontMemResourceEx (const_cast<void*> (data), (DWORD) dataSize,
  275. nullptr, &numInstalled);
  276. MemoryInputStream m (data, dataSize, false);
  277. name = TTFNameExtractor::getTypefaceNameFromFile (m);
  278. loadFont();
  279. }
  280. ~WindowsTypeface()
  281. {
  282. SelectObject (dc, previousFontH); // Replacing the previous font before deleting the DC avoids a warning in BoundsChecker
  283. DeleteDC (dc);
  284. if (fontH != 0)
  285. DeleteObject (fontH);
  286. if (memoryFont != 0)
  287. RemoveFontMemResourceEx (memoryFont);
  288. }
  289. float getAscent() const { return ascent; }
  290. float getDescent() const { return 1.0f - ascent; }
  291. float getHeightToPointsFactor() const { return heightToPointsFactor; }
  292. float getStringWidth (const String& text)
  293. {
  294. const CharPointer_UTF16 utf16 (text.toUTF16());
  295. const size_t numChars = utf16.length();
  296. HeapBlock<int16> results (numChars + 1);
  297. results[numChars] = -1;
  298. float x = 0;
  299. if (GetGlyphIndices (dc, utf16, (int) numChars, reinterpret_cast <WORD*> (results.getData()),
  300. GGI_MARK_NONEXISTING_GLYPHS) != GDI_ERROR)
  301. {
  302. for (size_t i = 0; i < numChars; ++i)
  303. x += getKerning (dc, results[i], results[i + 1]);
  304. }
  305. return x;
  306. }
  307. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  308. {
  309. const CharPointer_UTF16 utf16 (text.toUTF16());
  310. const size_t numChars = utf16.length();
  311. HeapBlock<int16> results (numChars + 1);
  312. results[numChars] = -1;
  313. float x = 0;
  314. if (GetGlyphIndices (dc, utf16, (int) numChars, reinterpret_cast <WORD*> (results.getData()),
  315. GGI_MARK_NONEXISTING_GLYPHS) != GDI_ERROR)
  316. {
  317. resultGlyphs.ensureStorageAllocated ((int) numChars);
  318. xOffsets.ensureStorageAllocated ((int) numChars + 1);
  319. for (size_t i = 0; i < numChars; ++i)
  320. {
  321. resultGlyphs.add (results[i]);
  322. xOffsets.add (x);
  323. x += getKerning (dc, results[i], results[i + 1]);
  324. }
  325. }
  326. xOffsets.add (x);
  327. }
  328. bool getOutlineForGlyph (int glyphNumber, Path& glyphPath)
  329. {
  330. if (glyphNumber < 0)
  331. glyphNumber = defaultGlyph;
  332. GLYPHMETRICS gm;
  333. // (although GetGlyphOutline returns a DWORD, it may be -1 on failure, so treat it as signed int..)
  334. const int bufSize = (int) GetGlyphOutline (dc, (UINT) glyphNumber, GGO_NATIVE | GGO_GLYPH_INDEX,
  335. &gm, 0, 0, &identityMatrix);
  336. if (bufSize > 0)
  337. {
  338. HeapBlock<char> data (bufSize);
  339. GetGlyphOutline (dc, (UINT) glyphNumber, GGO_NATIVE | GGO_GLYPH_INDEX, &gm,
  340. bufSize, data, &identityMatrix);
  341. const TTPOLYGONHEADER* pheader = reinterpret_cast<TTPOLYGONHEADER*> (data.getData());
  342. const float scaleX = 1.0f / tm.tmHeight;
  343. const float scaleY = -scaleX;
  344. while ((char*) pheader < data + bufSize)
  345. {
  346. glyphPath.startNewSubPath (scaleX * pheader->pfxStart.x.value,
  347. scaleY * pheader->pfxStart.y.value);
  348. const TTPOLYCURVE* curve = (const TTPOLYCURVE*) ((const char*) pheader + sizeof (TTPOLYGONHEADER));
  349. const char* const curveEnd = ((const char*) pheader) + pheader->cb;
  350. while ((const char*) curve < curveEnd)
  351. {
  352. if (curve->wType == TT_PRIM_LINE)
  353. {
  354. for (int i = 0; i < curve->cpfx; ++i)
  355. glyphPath.lineTo (scaleX * curve->apfx[i].x.value,
  356. scaleY * curve->apfx[i].y.value);
  357. }
  358. else if (curve->wType == TT_PRIM_QSPLINE)
  359. {
  360. for (int i = 0; i < curve->cpfx - 1; ++i)
  361. {
  362. const float x2 = scaleX * curve->apfx[i].x.value;
  363. const float y2 = scaleY * curve->apfx[i].y.value;
  364. float x3 = scaleX * curve->apfx[i + 1].x.value;
  365. float y3 = scaleY * curve->apfx[i + 1].y.value;
  366. if (i < curve->cpfx - 2)
  367. {
  368. x3 = 0.5f * (x2 + x3);
  369. y3 = 0.5f * (y2 + y3);
  370. }
  371. glyphPath.quadraticTo (x2, y2, x3, y3);
  372. }
  373. }
  374. curve = (const TTPOLYCURVE*) &(curve->apfx [curve->cpfx]);
  375. }
  376. pheader = (const TTPOLYGONHEADER*) curve;
  377. glyphPath.closeSubPath();
  378. }
  379. }
  380. return true;
  381. }
  382. private:
  383. static const MAT2 identityMatrix;
  384. HFONT fontH;
  385. HGDIOBJ previousFontH;
  386. HDC dc;
  387. TEXTMETRIC tm;
  388. HANDLE memoryFont;
  389. float ascent, heightToPointsFactor;
  390. int defaultGlyph, heightInPoints;
  391. struct KerningPair
  392. {
  393. int glyph1, glyph2;
  394. float kerning;
  395. bool operator== (const KerningPair& other) const noexcept
  396. {
  397. return glyph1 == other.glyph1 && glyph2 == other.glyph2;
  398. }
  399. bool operator< (const KerningPair& other) const noexcept
  400. {
  401. return glyph1 < other.glyph1
  402. || (glyph1 == other.glyph1 && glyph2 < other.glyph2);
  403. }
  404. };
  405. SortedSet<KerningPair> kerningPairs;
  406. void loadFont()
  407. {
  408. SetMapperFlags (dc, 0);
  409. SetMapMode (dc, MM_TEXT);
  410. LOGFONTW lf = { 0 };
  411. lf.lfCharSet = DEFAULT_CHARSET;
  412. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  413. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  414. lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  415. lf.lfQuality = PROOF_QUALITY;
  416. lf.lfItalic = (BYTE) (style == "Italic" ? TRUE : FALSE);
  417. lf.lfWeight = style == "Bold" ? FW_BOLD : FW_NORMAL;
  418. lf.lfHeight = -256;
  419. name.copyToUTF16 (lf.lfFaceName, sizeof (lf.lfFaceName));
  420. HFONT standardSizedFont = CreateFontIndirect (&lf);
  421. if (standardSizedFont != 0)
  422. {
  423. if ((previousFontH = SelectObject (dc, standardSizedFont)) != 0)
  424. {
  425. fontH = standardSizedFont;
  426. OUTLINETEXTMETRIC otm;
  427. if (GetOutlineTextMetrics (dc, sizeof (otm), &otm) != 0)
  428. {
  429. heightInPoints = otm.otmEMSquare;
  430. lf.lfHeight = -(int) heightInPoints;
  431. fontH = CreateFontIndirect (&lf);
  432. SelectObject (dc, fontH);
  433. DeleteObject (standardSizedFont);
  434. }
  435. }
  436. }
  437. if (GetTextMetrics (dc, &tm))
  438. {
  439. float dpi = (GetDeviceCaps (dc, LOGPIXELSX) + GetDeviceCaps (dc, LOGPIXELSY)) / 2.0f;
  440. heightToPointsFactor = (dpi / GetDeviceCaps (dc, LOGPIXELSY)) * heightInPoints / (float) tm.tmHeight;
  441. ascent = tm.tmAscent / (float) tm.tmHeight;
  442. defaultGlyph = getGlyphForChar (dc, tm.tmDefaultChar);
  443. createKerningPairs (dc, (float) tm.tmHeight);
  444. }
  445. }
  446. void createKerningPairs (HDC dc, const float height)
  447. {
  448. HeapBlock<KERNINGPAIR> rawKerning;
  449. const DWORD numKPs = GetKerningPairs (dc, 0, 0);
  450. rawKerning.calloc (numKPs);
  451. GetKerningPairs (dc, numKPs, rawKerning);
  452. kerningPairs.ensureStorageAllocated ((int) numKPs);
  453. for (DWORD i = 0; i < numKPs; ++i)
  454. {
  455. KerningPair kp;
  456. kp.glyph1 = getGlyphForChar (dc, rawKerning[i].wFirst);
  457. kp.glyph2 = getGlyphForChar (dc, rawKerning[i].wSecond);
  458. const int standardWidth = getGlyphWidth (dc, kp.glyph1);
  459. kp.kerning = (standardWidth + rawKerning[i].iKernAmount) / height;
  460. kerningPairs.add (kp);
  461. kp.glyph2 = -1; // add another entry for the standard width version..
  462. kp.kerning = standardWidth / height;
  463. kerningPairs.add (kp);
  464. }
  465. }
  466. static int getGlyphForChar (HDC dc, juce_wchar character)
  467. {
  468. const WCHAR charToTest[] = { (WCHAR) character, 0 };
  469. WORD index = 0;
  470. if (GetGlyphIndices (dc, charToTest, 1, &index, GGI_MARK_NONEXISTING_GLYPHS) == GDI_ERROR
  471. || index == 0xffff)
  472. return -1;
  473. return index;
  474. }
  475. static int getGlyphWidth (HDC dc, int glyphNumber)
  476. {
  477. GLYPHMETRICS gm;
  478. gm.gmCellIncX = 0;
  479. GetGlyphOutline (dc, (UINT) glyphNumber, GGO_NATIVE | GGO_GLYPH_INDEX, &gm, 0, 0, &identityMatrix);
  480. return gm.gmCellIncX;
  481. }
  482. float getKerning (HDC dc, const int glyph1, const int glyph2)
  483. {
  484. KerningPair kp;
  485. kp.glyph1 = glyph1;
  486. kp.glyph2 = glyph2;
  487. int index = kerningPairs.indexOf (kp);
  488. if (index < 0)
  489. {
  490. kp.glyph2 = -1;
  491. index = kerningPairs.indexOf (kp);
  492. if (index < 0)
  493. {
  494. kp.glyph2 = -1;
  495. kp.kerning = getGlyphWidth (dc, kp.glyph1) / (float) tm.tmHeight;
  496. kerningPairs.add (kp);
  497. return kp.kerning;
  498. }
  499. }
  500. return kerningPairs.getReference (index).kerning;
  501. }
  502. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WindowsTypeface)
  503. };
  504. const MAT2 WindowsTypeface::identityMatrix = { { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 1 } };
  505. Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  506. {
  507. #if JUCE_USE_DIRECTWRITE
  508. SharedResourcePointer<Direct2DFactories> factories;
  509. if (factories->systemFonts != nullptr)
  510. {
  511. ScopedPointer<WindowsDirectWriteTypeface> wtf (new WindowsDirectWriteTypeface (font, factories->systemFonts));
  512. if (wtf->loadedOk())
  513. return wtf.release();
  514. }
  515. #endif
  516. return new WindowsTypeface (font);
  517. }
  518. Typeface::Ptr Typeface::createSystemTypefaceFor (const void* data, size_t dataSize)
  519. {
  520. return new WindowsTypeface (data, dataSize);
  521. }
  522. void Typeface::scanFolderForFonts (const File&)
  523. {
  524. jassertfalse; // not implemented on this platform
  525. }