瀏覽代碼

Support for TrueType collections

Brian Fiete 4 年之前
父節點
當前提交
fb1d1aecc0
共有 3 個文件被更改,包括 32 次插入11 次删除
  1. 22 5
      BeefLibs/Beefy2D/src/gfx/Font.bf
  2. 10 1
      BeefySysLib/gfx/FTFont.cpp
  3. 0 5
      IDEHelper/Backend/BeMCContext.cpp

+ 22 - 5
BeefLibs/Beefy2D/src/gfx/Font.bf

@@ -171,16 +171,33 @@ namespace Beefy.gfx
 						{
 							if (valType == 1)
 							{
-								String fontName = new String(&fontNameArr);
+								String fontName = scope String(&fontNameArr);
 								int parenPos = fontName.IndexOf(" (");
 								if (parenPos != -1)
 									fontName.RemoveToEnd(parenPos);
 								fontName.ToUpper();
-								String fontPath = new String(&data);
-								if ((!fontPath.EndsWith(".TTF", .OrdinalIgnoreCase)) || (!sFontNameMap.TryAdd(fontName, fontPath)))
+								String fontPath = scope String(&data);
+								if ((!fontPath.EndsWith(".TTF", .OrdinalIgnoreCase)) && (!fontPath.EndsWith(".TTC", .OrdinalIgnoreCase)))
+									continue;
+
+								if (fontName.Contains('&'))
+								{
+									int collectionIdx = 0;
+									for (var namePart in fontName.Split('&', .RemoveEmptyEntries))
+									{
+										namePart.Trim();
+										if (sFontNameMap.TryAddAlt(namePart, var keyPtr, var valuePtr))
+										{
+											*keyPtr = new String(namePart);
+											*valuePtr = new $"{fontPath}@{collectionIdx}";
+											collectionIdx++;
+										}
+									}
+								}
+								else if (sFontNameMap.TryAdd(fontName, var keyPtr, var valuePtr))
 								{
-									delete fontName;
-									delete fontPath;
+									*keyPtr = new String(fontName);
+									*valuePtr = new String(fontPath);
 								}
 							}
 						}

+ 10 - 1
BeefySysLib/gfx/FTFont.cpp

@@ -144,7 +144,16 @@ bool FTFont::Load(const StringImpl& fileName, float pointSize)
 
 		face->mFileName = fileName;
 		FT_Face ftFace = NULL;
-		auto error = FT_New_Face(gFTLibrary, fileName.c_str(), 0, &ftFace);		
+
+		String useFileName = fileName;
+		int faceIdx = 0;
+		int atPos = (int)useFileName.IndexOf('@');
+		if (atPos != -1)
+		{
+			faceIdx = atoi(useFileName.c_str() + atPos + 1);
+			useFileName.RemoveToEnd(atPos);
+		}
+		auto error = FT_New_Face(gFTLibrary, useFileName.c_str(), faceIdx, &ftFace);		
 		face->mFTFace = ftFace;
 	}
 	else

+ 0 - 5
IDEHelper/Backend/BeMCContext.cpp

@@ -9910,11 +9910,6 @@ bool BeMCContext::DoLegalization()
 								if ((needRegDisable) &&
 									((!vregInfo->mDisableRAX) || (!vregInfo->mDisableRDX)))
 								{
-									if (mDebugging)
-									{
-										NOP;
-									}
-
 									vregInfo->mDisableRAX = true;
 									vregInfo->mDisableRDX = true;
 									isFinalRun = false;