Compare commits
66 Commits
0.7.0
...
a284edd130
@@ -3,12 +3,12 @@ using System;
|
|||||||
namespace Cryville.Common.ComponentModel {
|
namespace Cryville.Common.ComponentModel {
|
||||||
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
|
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
|
||||||
public class RangeAttribute : Attribute {
|
public class RangeAttribute : Attribute {
|
||||||
public RangeAttribute(float min, float max) {
|
public RangeAttribute(double min, double max) {
|
||||||
Min = min;
|
Min = min;
|
||||||
Max = max;
|
Max = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float Min { get; set; }
|
public double Min { get; set; }
|
||||||
public float Max { get; set; }
|
public double Max { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ using System;
|
|||||||
namespace Cryville.Common.ComponentModel {
|
namespace Cryville.Common.ComponentModel {
|
||||||
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
|
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
|
||||||
public class StepAttribute : Attribute {
|
public class StepAttribute : Attribute {
|
||||||
public StepAttribute(float step) {
|
public StepAttribute(double step) {
|
||||||
Step = step;
|
Step = step;
|
||||||
}
|
}
|
||||||
public float Step { get; set; }
|
public double Step { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,295 +6,295 @@ using System.Linq;
|
|||||||
namespace Cryville.Common.Font {
|
namespace Cryville.Common.Font {
|
||||||
public abstract class FontMatcher {
|
public abstract class FontMatcher {
|
||||||
protected FontManager Manager { get; private set; }
|
protected FontManager Manager { get; private set; }
|
||||||
public FontMatcher(FontManager manafer) { Manager = manafer; }
|
public FontMatcher(FontManager manager) { Manager = manager; }
|
||||||
public abstract IEnumerable<Typeface> MatchScript(string script = null, bool distinctFamily = false);
|
public abstract IEnumerable<Typeface> MatchScript(string script = null, bool distinctFamily = false);
|
||||||
}
|
}
|
||||||
public class FallbackListFontMatcher : FontMatcher {
|
public class FallbackListFontMatcher : FontMatcher {
|
||||||
public Dictionary<string, List<string>> MapScriptToTypefaces = new Dictionary<string, List<string>>();
|
public Dictionary<string, List<string>> MapScriptToTypefaces = new Dictionary<string, List<string>>();
|
||||||
public void LoadDefaultWindowsFallbackList() {
|
public static Dictionary<string, List<string>> GetDefaultWindowsFallbackMap() {
|
||||||
if (Environment.OSVersion.Platform != PlatformID.Win32NT) return;
|
var map = new Dictionary<string, List<string>>();
|
||||||
MapScriptToTypefaces.Clear();
|
ScriptUtils.FillKeysWithScripts(map, () => new List<string>());
|
||||||
ScriptUtils.FillKeysWithScripts(MapScriptToTypefaces, () => new List<string>());
|
|
||||||
// Reference: https://github.com/chromium/chromium/blob/main/third_party/blink/renderer/platform/fonts/win/font_fallback_win.cc
|
// Reference: https://github.com/chromium/chromium/blob/main/third_party/blink/renderer/platform/fonts/win/font_fallback_win.cc
|
||||||
MapScriptToTypefaces["zyyy"].Insert(0, "SimSun"); // Custom
|
map["zyyy"].Insert(0, "SimSun"); // Custom
|
||||||
MapScriptToTypefaces["zyyy"].Insert(0, "SimHei"); // Custom
|
map["zyyy"].Insert(0, "SimHei"); // Custom
|
||||||
MapScriptToTypefaces["zyyy"].Insert(0, "Microsoft YaHei"); // Custom
|
map["zyyy"].Insert(0, "Microsoft YaHei"); // Custom
|
||||||
MapScriptToTypefaces["zyyy"].Insert(0, "Arial");
|
map["zyyy"].Insert(0, "Arial");
|
||||||
MapScriptToTypefaces["zyyy"].Insert(0, "Times New Roman");
|
map["zyyy"].Insert(0, "Times New Roman");
|
||||||
MapScriptToTypefaces["zyyy"].Insert(0, "Segoe UI"); // Custom
|
map["zyyy"].Insert(0, "Segoe UI"); // Custom
|
||||||
MapScriptToTypefaces["arab"].Insert(0, "Tahoma");
|
map["arab"].Insert(0, "Tahoma");
|
||||||
MapScriptToTypefaces["cyrl"].Insert(0, "Times New Roman");
|
map["cyrl"].Insert(0, "Times New Roman");
|
||||||
MapScriptToTypefaces["grek"].Insert(0, "Times New Roman");
|
map["grek"].Insert(0, "Times New Roman");
|
||||||
MapScriptToTypefaces["hebr"].Insert(0, "David");
|
map["hebr"].Insert(0, "David");
|
||||||
MapScriptToTypefaces["jpan"].Insert(0, "MS PGothic");
|
map["jpan"].Insert(0, "MS PGothic");
|
||||||
MapScriptToTypefaces["latn"].Insert(0, "Times New Roman");
|
map["latn"].Insert(0, "Times New Roman");
|
||||||
MapScriptToTypefaces["hans"].Insert(0, "SimSun");
|
map["hans"].Insert(0, "SimSun");
|
||||||
MapScriptToTypefaces["hans"].Insert(0, "SimHei"); // Custom
|
map["hans"].Insert(0, "SimHei"); // Custom
|
||||||
MapScriptToTypefaces["thai"].Insert(0, "Tahoma");
|
map["thai"].Insert(0, "Tahoma");
|
||||||
MapScriptToTypefaces["hans"].Insert(0, "PMingLiU");
|
map["hans"].Insert(0, "PMingLiU");
|
||||||
// Reference: https://learn.microsoft.com/en-us/globalization/input/font-support
|
// Reference: https://learn.microsoft.com/en-us/globalization/input/font-support
|
||||||
var ver = Environment.OSVersion.Version;
|
var ver = Environment.OSVersion.Version;
|
||||||
if (ver >= new Version(5, 0)) { // Windows 2000
|
if (ver >= new Version(5, 0)) { // Windows 2000
|
||||||
MapScriptToTypefaces["armn"].Insert(0, "Sylfaen");
|
map["armn"].Insert(0, "Sylfaen");
|
||||||
MapScriptToTypefaces["deva"].Insert(0, "Mangal");
|
map["deva"].Insert(0, "Mangal");
|
||||||
MapScriptToTypefaces["geor"].Insert(0, "Sylfaen");
|
map["geor"].Insert(0, "Sylfaen");
|
||||||
MapScriptToTypefaces["taml"].Insert(0, "Latha");
|
map["taml"].Insert(0, "Latha");
|
||||||
}
|
}
|
||||||
if (ver >= new Version(5, 1)) { // Windows XP
|
if (ver >= new Version(5, 1)) { // Windows XP
|
||||||
MapScriptToTypefaces["gujr"].Insert(0, "Shruti");
|
map["gujr"].Insert(0, "Shruti");
|
||||||
MapScriptToTypefaces["guru"].Insert(0, "Raavi");
|
map["guru"].Insert(0, "Raavi");
|
||||||
MapScriptToTypefaces["knda"].Insert(0, "Tunga");
|
map["knda"].Insert(0, "Tunga");
|
||||||
MapScriptToTypefaces["syrc"].Insert(0, "Estrangelo Edessa");
|
map["syrc"].Insert(0, "Estrangelo Edessa");
|
||||||
MapScriptToTypefaces["telu"].Insert(0, "Gautami");
|
map["telu"].Insert(0, "Gautami");
|
||||||
MapScriptToTypefaces["thaa"].Insert(0, "MV Boli");
|
map["thaa"].Insert(0, "MV Boli");
|
||||||
// SP2
|
// SP2
|
||||||
MapScriptToTypefaces["beng"].Insert(0, "Vrinda");
|
map["beng"].Insert(0, "Vrinda");
|
||||||
MapScriptToTypefaces["mlym"].Insert(0, "Kartika");
|
map["mlym"].Insert(0, "Kartika");
|
||||||
}
|
}
|
||||||
if (ver >= new Version(6, 0)) { // Windows Vista
|
if (ver >= new Version(6, 0)) { // Windows Vista
|
||||||
MapScriptToTypefaces["cans"].Insert(0, "Euphemia");
|
map["cans"].Insert(0, "Euphemia");
|
||||||
MapScriptToTypefaces["cher"].Insert(0, "Plantagenet");
|
map["cher"].Insert(0, "Plantagenet");
|
||||||
MapScriptToTypefaces["ethi"].Insert(0, "Nyala");
|
map["ethi"].Insert(0, "Nyala");
|
||||||
MapScriptToTypefaces["khmr"].Insert(0, "DaunPenh MoolBoran");
|
map["khmr"].Insert(0, "DaunPenh MoolBoran");
|
||||||
MapScriptToTypefaces["laoo"].Insert(0, "DokChampa");
|
map["laoo"].Insert(0, "DokChampa");
|
||||||
MapScriptToTypefaces["mong"].Insert(0, "Mongolian Baiti");
|
map["mong"].Insert(0, "Mongolian Baiti");
|
||||||
MapScriptToTypefaces["orya"].Insert(0, "Kalinga");
|
map["orya"].Insert(0, "Kalinga");
|
||||||
MapScriptToTypefaces["sinh"].Insert(0, "Iskoola Pota");
|
map["sinh"].Insert(0, "Iskoola Pota");
|
||||||
MapScriptToTypefaces["tibt"].Insert(0, "Microsoft Himalaya");
|
map["tibt"].Insert(0, "Microsoft Himalaya");
|
||||||
MapScriptToTypefaces["yiii"].Insert(0, "Microsoft Yi Baiti");
|
map["yiii"].Insert(0, "Microsoft Yi Baiti");
|
||||||
MapScriptToTypefaces["arab"].Insert(0, "Segoe UI");
|
map["arab"].Insert(0, "Segoe UI");
|
||||||
MapScriptToTypefaces["cyrl"].Insert(0, "Segoe UI");
|
map["cyrl"].Insert(0, "Segoe UI");
|
||||||
MapScriptToTypefaces["grek"].Insert(0, "Segoe UI");
|
map["grek"].Insert(0, "Segoe UI");
|
||||||
MapScriptToTypefaces["latn"].Insert(0, "Segoe UI");
|
map["latn"].Insert(0, "Segoe UI");
|
||||||
MapScriptToTypefaces["hans"].Add("SimSun-ExtB");
|
map["hans"].Add("SimSun-ExtB");
|
||||||
MapScriptToTypefaces["hant"].Add("MingLiU-ExtB");
|
map["hant"].Add("MingLiU-ExtB");
|
||||||
MapScriptToTypefaces["hant"].Add("MingLiU_HKSCS-ExtB");
|
map["hant"].Add("MingLiU_HKSCS-ExtB");
|
||||||
MapScriptToTypefaces["arab"].Add("Microsoft Uighur");
|
map["arab"].Add("Microsoft Uighur");
|
||||||
MapScriptToTypefaces["zmth"].Insert(0, "Cambria Math");
|
map["zmth"].Insert(0, "Cambria Math");
|
||||||
// Reference: https://en.wikipedia.org/wiki/List_of_CJK_fonts
|
// Reference: https://en.wikipedia.org/wiki/List_of_CJK_fonts
|
||||||
MapScriptToTypefaces["jpan"].Insert(0, "Meiryo");
|
map["jpan"].Insert(0, "Meiryo");
|
||||||
MapScriptToTypefaces["hans"].Insert(0, "Microsoft YaHei");
|
map["hans"].Insert(0, "Microsoft YaHei");
|
||||||
}
|
}
|
||||||
if (ver >= new Version(6, 1)) { // Windows 7
|
if (ver >= new Version(6, 1)) { // Windows 7
|
||||||
MapScriptToTypefaces["brai"].Insert(0, "Segoe UI Symbol");
|
map["brai"].Insert(0, "Segoe UI Symbol");
|
||||||
MapScriptToTypefaces["dsrt"].Insert(0, "Segoe UI Symbol");
|
map["dsrt"].Insert(0, "Segoe UI Symbol");
|
||||||
MapScriptToTypefaces["talu"].Insert(0, "Microsoft New Tai Lue");
|
map["talu"].Insert(0, "Microsoft New Tai Lue");
|
||||||
MapScriptToTypefaces["ogam"].Insert(0, "Segoe UI Symbol");
|
map["ogam"].Insert(0, "Segoe UI Symbol");
|
||||||
MapScriptToTypefaces["osma"].Insert(0, "Ebrima");
|
map["osma"].Insert(0, "Ebrima");
|
||||||
MapScriptToTypefaces["phag"].Insert(0, "Microsoft PhagsPa");
|
map["phag"].Insert(0, "Microsoft PhagsPa");
|
||||||
MapScriptToTypefaces["runr"].Insert(0, "Segoe UI Symbol");
|
map["runr"].Insert(0, "Segoe UI Symbol");
|
||||||
MapScriptToTypefaces["zsym"].Insert(0, "Segoe UI Symbol");
|
map["zsym"].Insert(0, "Segoe UI Symbol");
|
||||||
MapScriptToTypefaces["tale"].Insert(0, "Microsoft Tai Le");
|
map["tale"].Insert(0, "Microsoft Tai Le");
|
||||||
MapScriptToTypefaces["tfng"].Insert(0, "Ebrima");
|
map["tfng"].Insert(0, "Ebrima");
|
||||||
MapScriptToTypefaces["vaii"].Insert(0, "Ebrima");
|
map["vaii"].Insert(0, "Ebrima");
|
||||||
}
|
}
|
||||||
if (ver >= new Version(6, 2)) { // Windows 8
|
if (ver >= new Version(6, 2)) { // Windows 8
|
||||||
MapScriptToTypefaces["glag"].Insert(0, "Segoe UI Symbol");
|
map["glag"].Insert(0, "Segoe UI Symbol");
|
||||||
MapScriptToTypefaces["goth"].Insert(0, "Segoe UI Symbol");
|
map["goth"].Insert(0, "Segoe UI Symbol");
|
||||||
MapScriptToTypefaces["hang"].Add("Malgun Gothic");
|
map["hang"].Add("Malgun Gothic");
|
||||||
MapScriptToTypefaces["ital"].Insert(0, "Segoe UI Symbol");
|
map["ital"].Insert(0, "Segoe UI Symbol");
|
||||||
MapScriptToTypefaces["lisu"].Insert(0, "Segoe UI");
|
map["lisu"].Insert(0, "Segoe UI");
|
||||||
MapScriptToTypefaces["mymr"].Insert(0, "Myanmar Text");
|
map["mymr"].Insert(0, "Myanmar Text");
|
||||||
MapScriptToTypefaces["nkoo"].Insert(0, "Ebrima");
|
map["nkoo"].Insert(0, "Ebrima");
|
||||||
MapScriptToTypefaces["orkh"].Insert(0, "Segoe UI Symbol");
|
map["orkh"].Insert(0, "Segoe UI Symbol");
|
||||||
MapScriptToTypefaces["ethi"].Insert(0, "Ebrima");
|
map["ethi"].Insert(0, "Ebrima");
|
||||||
MapScriptToTypefaces["cans"].Insert(0, "Gadugi");
|
map["cans"].Insert(0, "Gadugi");
|
||||||
MapScriptToTypefaces["hant"].Insert(0, "Microsoft JhengHei UI");
|
map["hant"].Insert(0, "Microsoft JhengHei UI");
|
||||||
MapScriptToTypefaces["hans"].Insert(0, "Microsoft YaHei UI");
|
map["hans"].Insert(0, "Microsoft YaHei UI");
|
||||||
MapScriptToTypefaces["beng"].Insert(0, "Nirmala UI");
|
map["beng"].Insert(0, "Nirmala UI");
|
||||||
MapScriptToTypefaces["deva"].Insert(0, "Nirmala UI");
|
map["deva"].Insert(0, "Nirmala UI");
|
||||||
MapScriptToTypefaces["gujr"].Insert(0, "Nirmala UI");
|
map["gujr"].Insert(0, "Nirmala UI");
|
||||||
MapScriptToTypefaces["guru"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
|
map["guru"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
|
||||||
MapScriptToTypefaces["knda"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
|
map["knda"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
|
||||||
MapScriptToTypefaces["mlym"].Insert(0, "Nirmala UI");
|
map["mlym"].Insert(0, "Nirmala UI");
|
||||||
MapScriptToTypefaces["orya"].Insert(0, "Nirmala UI");
|
map["orya"].Insert(0, "Nirmala UI");
|
||||||
MapScriptToTypefaces["sinh"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
|
map["sinh"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
|
||||||
MapScriptToTypefaces["taml"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
|
map["taml"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
|
||||||
MapScriptToTypefaces["telu"].Insert(0, "Nirmala UI");
|
map["telu"].Insert(0, "Nirmala UI");
|
||||||
MapScriptToTypefaces["armn"].Insert(0, "Segoe UI");
|
map["armn"].Insert(0, "Segoe UI");
|
||||||
MapScriptToTypefaces["geor"].Insert(0, "Segoe UI");
|
map["geor"].Insert(0, "Segoe UI");
|
||||||
MapScriptToTypefaces["hebr"].Insert(0, "Segoe UI");
|
map["hebr"].Insert(0, "Segoe UI");
|
||||||
}
|
}
|
||||||
if (ver >= new Version(6, 3)) { // Windows 8.1
|
if (ver >= new Version(6, 3)) { // Windows 8.1
|
||||||
MapScriptToTypefaces["bugi"].Insert(0, "Leelawadee UI");
|
map["bugi"].Insert(0, "Leelawadee UI");
|
||||||
MapScriptToTypefaces["copt"].Insert(0, "Segoe UI Symbol");
|
map["copt"].Insert(0, "Segoe UI Symbol");
|
||||||
MapScriptToTypefaces["java"].Insert(0, "Javanese Text");
|
map["java"].Insert(0, "Javanese Text");
|
||||||
MapScriptToTypefaces["merc"].Insert(0, "Segoe UI Symbol");
|
map["merc"].Insert(0, "Segoe UI Symbol");
|
||||||
MapScriptToTypefaces["olck"].Insert(0, "Nirmala UI");
|
map["olck"].Insert(0, "Nirmala UI");
|
||||||
MapScriptToTypefaces["sora"].Insert(0, "Nirmala UI");
|
map["sora"].Insert(0, "Nirmala UI");
|
||||||
MapScriptToTypefaces["khmr"].Insert(0, "Leelawadee UI");
|
map["khmr"].Insert(0, "Leelawadee UI");
|
||||||
MapScriptToTypefaces["laoo"].Insert(0, "Leelawadee UI");
|
map["laoo"].Insert(0, "Leelawadee UI");
|
||||||
MapScriptToTypefaces["thai"].Insert(0, "Leelawadee UI");
|
map["thai"].Insert(0, "Leelawadee UI");
|
||||||
MapScriptToTypefaces["zsye"].Insert(0, "Segoe UI Emoji");
|
map["zsye"].Insert(0, "Segoe UI Emoji");
|
||||||
}
|
}
|
||||||
if (ver >= new Version(10, 0)) { // Windows 10
|
if (ver >= new Version(10, 0)) { // Windows 10
|
||||||
MapScriptToTypefaces["brah"].Insert(0, "Segoe UI Historic");
|
map["brah"].Insert(0, "Segoe UI Historic");
|
||||||
MapScriptToTypefaces["cari"].Insert(0, "Segoe UI Historic");
|
map["cari"].Insert(0, "Segoe UI Historic");
|
||||||
MapScriptToTypefaces["cprt"].Insert(0, "Segoe UI Historic");
|
map["cprt"].Insert(0, "Segoe UI Historic");
|
||||||
MapScriptToTypefaces["egyp"].Insert(0, "Segoe UI Historic");
|
map["egyp"].Insert(0, "Segoe UI Historic");
|
||||||
MapScriptToTypefaces["armi"].Insert(0, "Segoe UI Historic");
|
map["armi"].Insert(0, "Segoe UI Historic");
|
||||||
MapScriptToTypefaces["phli"].Insert(0, "Segoe UI Historic");
|
map["phli"].Insert(0, "Segoe UI Historic");
|
||||||
MapScriptToTypefaces["prti"].Insert(0, "Segoe UI Historic");
|
map["prti"].Insert(0, "Segoe UI Historic");
|
||||||
MapScriptToTypefaces["khar"].Insert(0, "Segoe UI Historic");
|
map["khar"].Insert(0, "Segoe UI Historic");
|
||||||
MapScriptToTypefaces["lyci"].Insert(0, "Segoe UI Historic");
|
map["lyci"].Insert(0, "Segoe UI Historic");
|
||||||
MapScriptToTypefaces["lydi"].Insert(0, "Segoe UI Historic");
|
map["lydi"].Insert(0, "Segoe UI Historic");
|
||||||
MapScriptToTypefaces["phnx"].Insert(0, "Segoe UI Historic");
|
map["phnx"].Insert(0, "Segoe UI Historic");
|
||||||
MapScriptToTypefaces["xpeo"].Insert(0, "Segoe UI Historic");
|
map["xpeo"].Insert(0, "Segoe UI Historic");
|
||||||
MapScriptToTypefaces["sarb"].Insert(0, "Segoe UI Historic");
|
map["sarb"].Insert(0, "Segoe UI Historic");
|
||||||
MapScriptToTypefaces["shaw"].Insert(0, "Segoe UI Historic");
|
map["shaw"].Insert(0, "Segoe UI Historic");
|
||||||
MapScriptToTypefaces["xsux"].Insert(0, "Segoe UI Historic");
|
map["xsux"].Insert(0, "Segoe UI Historic");
|
||||||
MapScriptToTypefaces["ugar"].Insert(0, "Segoe UI Historic");
|
map["ugar"].Insert(0, "Segoe UI Historic");
|
||||||
// Segoe UI Symbol -> Segoe UI Historic
|
// Segoe UI Symbol -> Segoe UI Historic
|
||||||
MapScriptToTypefaces["glag"].Insert(0, "Segoe UI Historic");
|
map["glag"].Insert(0, "Segoe UI Historic");
|
||||||
MapScriptToTypefaces["goth"].Insert(0, "Segoe UI Historic");
|
map["goth"].Insert(0, "Segoe UI Historic");
|
||||||
MapScriptToTypefaces["merc"].Insert(0, "Segoe UI Historic");
|
map["merc"].Insert(0, "Segoe UI Historic");
|
||||||
MapScriptToTypefaces["ogam"].Insert(0, "Segoe UI Historic");
|
map["ogam"].Insert(0, "Segoe UI Historic");
|
||||||
MapScriptToTypefaces["ital"].Insert(0, "Segoe UI Historic");
|
map["ital"].Insert(0, "Segoe UI Historic");
|
||||||
MapScriptToTypefaces["orkh"].Insert(0, "Segoe UI Historic");
|
map["orkh"].Insert(0, "Segoe UI Historic");
|
||||||
MapScriptToTypefaces["runr"].Insert(0, "Segoe UI Historic");
|
map["runr"].Insert(0, "Segoe UI Historic");
|
||||||
//
|
//
|
||||||
MapScriptToTypefaces["jpan"].Insert(0, "Yu Gothic UI");
|
map["jpan"].Insert(0, "Yu Gothic UI");
|
||||||
MapScriptToTypefaces["zsym"].Add("Segoe MDL2 Assets");
|
map["zsym"].Add("Segoe MDL2 Assets");
|
||||||
}
|
}
|
||||||
|
return map;
|
||||||
}
|
}
|
||||||
public void LoadDefaultAndroidFallbackList() {
|
public static Dictionary<string, List<string>> GetDefaultAndroidFallbackMap() {
|
||||||
if (Environment.OSVersion.Platform != PlatformID.Unix) return;
|
var map = new Dictionary<string, List<string>>();
|
||||||
MapScriptToTypefaces.Clear();
|
ScriptUtils.FillKeysWithScripts(map, () => new List<string>());
|
||||||
ScriptUtils.FillKeysWithScripts(MapScriptToTypefaces, () => new List<string>());
|
map["zyyy"].Insert(0, "Noto Sans CJK TC"); // TODO Modify default fallback
|
||||||
MapScriptToTypefaces["zyyy"].Insert(0, "Noto Sans CJK TC"); // TODO Modify default fallback
|
map["zyyy"].Insert(0, "Noto Sans CJK JP");
|
||||||
MapScriptToTypefaces["zyyy"].Insert(0, "Noto Sans CJK JP");
|
map["zyyy"].Insert(0, "Noto Sans CJK SC");
|
||||||
MapScriptToTypefaces["zyyy"].Insert(0, "Noto Sans CJK SC");
|
map["zyyy"].Insert(0, "Roboto");
|
||||||
MapScriptToTypefaces["zyyy"].Insert(0, "Roboto");
|
map["zsye"].Insert(0, "Noto Color Emoji");
|
||||||
MapScriptToTypefaces["zsye"].Insert(0, "Noto Color Emoji");
|
map["zsye"].Add("Noto Color Emoji Flags");
|
||||||
MapScriptToTypefaces["zsye"].Add("Noto Color Emoji Flags");
|
map["arab"].Insert(0, "Noto Naskh Arabic");
|
||||||
MapScriptToTypefaces["arab"].Insert(0, "Noto Naskh Arabic");
|
map["adlm"].Insert(0, "Noto Sans Adlam");
|
||||||
MapScriptToTypefaces["adlm"].Insert(0, "Noto Sans Adlam");
|
map["ahom"].Insert(0, "Noto Sans Ahom");
|
||||||
MapScriptToTypefaces["ahom"].Insert(0, "Noto Sans Ahom");
|
map["hluw"].Insert(0, "Noto Sans Anatolian Hieroglyphs");
|
||||||
MapScriptToTypefaces["hluw"].Insert(0, "Noto Sans Anatolian Hieroglyphs");
|
map["armn"].Insert(0, "Noto Sans Armenian");
|
||||||
MapScriptToTypefaces["armn"].Insert(0, "Noto Sans Armenian");
|
map["avst"].Insert(0, "Noto Sans Avestan");
|
||||||
MapScriptToTypefaces["avst"].Insert(0, "Noto Sans Avestan");
|
map["bali"].Insert(0, "Noto Sans Balinese");
|
||||||
MapScriptToTypefaces["bali"].Insert(0, "Noto Sans Balinese");
|
map["bamu"].Insert(0, "Noto Sans Bamum");
|
||||||
MapScriptToTypefaces["bamu"].Insert(0, "Noto Sans Bamum");
|
map["bass"].Insert(0, "Noto Sans Bassa Vah");
|
||||||
MapScriptToTypefaces["bass"].Insert(0, "Noto Sans Bassa Vah");
|
map["batk"].Insert(0, "Noto Sans Batak");
|
||||||
MapScriptToTypefaces["batk"].Insert(0, "Noto Sans Batak");
|
map["beng"].Insert(0, "Noto Sans Bengali");
|
||||||
MapScriptToTypefaces["beng"].Insert(0, "Noto Sans Bengali");
|
map["bhks"].Insert(0, "Noto Sans Bhaiksuki");
|
||||||
MapScriptToTypefaces["bhks"].Insert(0, "Noto Sans Bhaiksuki");
|
map["brah"].Insert(0, "Noto Sans Brahmi");
|
||||||
MapScriptToTypefaces["brah"].Insert(0, "Noto Sans Brahmi");
|
map["bugi"].Insert(0, "Noto Sans Buginese");
|
||||||
MapScriptToTypefaces["bugi"].Insert(0, "Noto Sans Buginese");
|
map["buhd"].Insert(0, "Noto Sans Buhid");
|
||||||
MapScriptToTypefaces["buhd"].Insert(0, "Noto Sans Buhid");
|
map["jpan"].Insert(0, "Noto Sans CJK JP");
|
||||||
MapScriptToTypefaces["jpan"].Insert(0, "Noto Sans CJK JP");
|
map["kore"].Insert(0, "Noto Sans CJK KR");
|
||||||
MapScriptToTypefaces["kore"].Insert(0, "Noto Sans CJK KR");
|
map["hans"].Insert(0, "Noto Sans CJK SC");
|
||||||
MapScriptToTypefaces["hans"].Insert(0, "Noto Sans CJK SC");
|
map["hant"].Insert(0, "Noto Sans CJK TC");
|
||||||
MapScriptToTypefaces["hant"].Insert(0, "Noto Sans CJK TC");
|
map["hant"].Add("Noto Sans CJK HK");
|
||||||
MapScriptToTypefaces["hant"].Add("Noto Sans CJK HK");
|
map["cans"].Insert(0, "Noto Sans Canadian Aboriginal");
|
||||||
MapScriptToTypefaces["cans"].Insert(0, "Noto Sans Canadian Aboriginal");
|
map["cari"].Insert(0, "Noto Sans Carian");
|
||||||
MapScriptToTypefaces["cari"].Insert(0, "Noto Sans Carian");
|
map["cakm"].Insert(0, "Noto Sans Chakma");
|
||||||
MapScriptToTypefaces["cakm"].Insert(0, "Noto Sans Chakma");
|
map["cham"].Insert(0, "Noto Sans Cham");
|
||||||
MapScriptToTypefaces["cham"].Insert(0, "Noto Sans Cham");
|
map["cher"].Insert(0, "Noto Sans Cherokee");
|
||||||
MapScriptToTypefaces["cher"].Insert(0, "Noto Sans Cherokee");
|
map["copt"].Insert(0, "Noto Sans Coptic");
|
||||||
MapScriptToTypefaces["copt"].Insert(0, "Noto Sans Coptic");
|
map["xsux"].Insert(0, "Noto Sans Cuneiform");
|
||||||
MapScriptToTypefaces["xsux"].Insert(0, "Noto Sans Cuneiform");
|
map["cprt"].Insert(0, "Noto Sans Cypriot");
|
||||||
MapScriptToTypefaces["cprt"].Insert(0, "Noto Sans Cypriot");
|
map["dsrt"].Insert(0, "Noto Sans Deseret");
|
||||||
MapScriptToTypefaces["dsrt"].Insert(0, "Noto Sans Deseret");
|
map["deva"].Insert(0, "Noto Sans Devanagari");
|
||||||
MapScriptToTypefaces["deva"].Insert(0, "Noto Sans Devanagari");
|
map["egyp"].Insert(0, "Noto Sans Egyptian Hieroglyphs");
|
||||||
MapScriptToTypefaces["egyp"].Insert(0, "Noto Sans Egyptian Hieroglyphs");
|
map["elba"].Insert(0, "Noto Sans Elbasan");
|
||||||
MapScriptToTypefaces["elba"].Insert(0, "Noto Sans Elbasan");
|
map["ethi"].Insert(0, "Noto Sans Ethiopic");
|
||||||
MapScriptToTypefaces["ethi"].Insert(0, "Noto Sans Ethiopic");
|
map["geor"].Insert(0, "Noto Sans Georgian");
|
||||||
MapScriptToTypefaces["geor"].Insert(0, "Noto Sans Georgian");
|
map["glag"].Insert(0, "Noto Sans Glagolitic");
|
||||||
MapScriptToTypefaces["glag"].Insert(0, "Noto Sans Glagolitic");
|
map["goth"].Insert(0, "Noto Sans Gothic");
|
||||||
MapScriptToTypefaces["goth"].Insert(0, "Noto Sans Gothic");
|
map["gran"].Insert(0, "Noto Sans Grantha");
|
||||||
MapScriptToTypefaces["gran"].Insert(0, "Noto Sans Grantha");
|
map["gujr"].Insert(0, "Noto Sans Gujarati");
|
||||||
MapScriptToTypefaces["gujr"].Insert(0, "Noto Sans Gujarati");
|
map["gong"].Insert(0, "Noto Sans Gunjala Gondi");
|
||||||
MapScriptToTypefaces["gong"].Insert(0, "Noto Sans Gunjala Gondi");
|
map["guru"].Insert(0, "Noto Sans Gurmukhi");
|
||||||
MapScriptToTypefaces["guru"].Insert(0, "Noto Sans Gurmukhi");
|
map["rohg"].Insert(0, "Noto Sans Hanifi Rohingya");
|
||||||
MapScriptToTypefaces["rohg"].Insert(0, "Noto Sans Hanifi Rohingya");
|
map["hano"].Insert(0, "Noto Sans Hanunoo");
|
||||||
MapScriptToTypefaces["hano"].Insert(0, "Noto Sans Hanunoo");
|
map["hatr"].Insert(0, "Noto Sans Hatran");
|
||||||
MapScriptToTypefaces["hatr"].Insert(0, "Noto Sans Hatran");
|
map["hebr"].Insert(0, "Noto Sans Hebrew");
|
||||||
MapScriptToTypefaces["hebr"].Insert(0, "Noto Sans Hebrew");
|
map["armi"].Insert(0, "Noto Sans Imperial Aramaic");
|
||||||
MapScriptToTypefaces["armi"].Insert(0, "Noto Sans Imperial Aramaic");
|
map["phli"].Insert(0, "Noto Sans Inscriptional Pahlavi");
|
||||||
MapScriptToTypefaces["phli"].Insert(0, "Noto Sans Inscriptional Pahlavi");
|
map["prti"].Insert(0, "Noto Sans Inscriptional Parthian");
|
||||||
MapScriptToTypefaces["prti"].Insert(0, "Noto Sans Inscriptional Parthian");
|
map["java"].Insert(0, "Noto Sans Javanese");
|
||||||
MapScriptToTypefaces["java"].Insert(0, "Noto Sans Javanese");
|
map["kthi"].Insert(0, "Noto Sans Kaithi");
|
||||||
MapScriptToTypefaces["kthi"].Insert(0, "Noto Sans Kaithi");
|
map["knda"].Insert(0, "Noto Sans Kannada");
|
||||||
MapScriptToTypefaces["knda"].Insert(0, "Noto Sans Kannada");
|
map["kali"].Insert(0, "Noto Sans KayahLi");
|
||||||
MapScriptToTypefaces["kali"].Insert(0, "Noto Sans KayahLi");
|
map["khar"].Insert(0, "Noto Sans Kharoshthi");
|
||||||
MapScriptToTypefaces["khar"].Insert(0, "Noto Sans Kharoshthi");
|
map["khmr"].Insert(0, "Noto Sans Khmer");
|
||||||
MapScriptToTypefaces["khmr"].Insert(0, "Noto Sans Khmer");
|
map["khoj"].Insert(0, "Noto Sans Khojki");
|
||||||
MapScriptToTypefaces["khoj"].Insert(0, "Noto Sans Khojki");
|
map["laoo"].Insert(0, "Noto Sans Lao");
|
||||||
MapScriptToTypefaces["laoo"].Insert(0, "Noto Sans Lao");
|
map["lepc"].Insert(0, "Noto Sans Lepcha");
|
||||||
MapScriptToTypefaces["lepc"].Insert(0, "Noto Sans Lepcha");
|
map["limb"].Insert(0, "Noto Sans Limbu");
|
||||||
MapScriptToTypefaces["limb"].Insert(0, "Noto Sans Limbu");
|
map["lina"].Insert(0, "Noto Sans Linear A");
|
||||||
MapScriptToTypefaces["lina"].Insert(0, "Noto Sans Linear A");
|
map["linb"].Insert(0, "Noto Sans Linear B");
|
||||||
MapScriptToTypefaces["linb"].Insert(0, "Noto Sans Linear B");
|
map["lisu"].Insert(0, "Noto Sans Lisu");
|
||||||
MapScriptToTypefaces["lisu"].Insert(0, "Noto Sans Lisu");
|
map["lyci"].Insert(0, "Noto Sans Lycian");
|
||||||
MapScriptToTypefaces["lyci"].Insert(0, "Noto Sans Lycian");
|
map["lydi"].Insert(0, "Noto Sans Lydian");
|
||||||
MapScriptToTypefaces["lydi"].Insert(0, "Noto Sans Lydian");
|
map["mlym"].Insert(0, "Noto Sans Malayalam");
|
||||||
MapScriptToTypefaces["mlym"].Insert(0, "Noto Sans Malayalam");
|
map["mand"].Insert(0, "Noto Sans Mandiac");
|
||||||
MapScriptToTypefaces["mand"].Insert(0, "Noto Sans Mandiac");
|
map["mani"].Insert(0, "Noto Sans Manichaean");
|
||||||
MapScriptToTypefaces["mani"].Insert(0, "Noto Sans Manichaean");
|
map["marc"].Insert(0, "Noto Sans Marchen");
|
||||||
MapScriptToTypefaces["marc"].Insert(0, "Noto Sans Marchen");
|
map["gonm"].Insert(0, "Noto Sans Masaram Gondi");
|
||||||
MapScriptToTypefaces["gonm"].Insert(0, "Noto Sans Masaram Gondi");
|
map["medf"].Insert(0, "Noto Sans Medefaidrin");
|
||||||
MapScriptToTypefaces["medf"].Insert(0, "Noto Sans Medefaidrin");
|
map["mtei"].Insert(0, "Noto Sans Meetei Mayek");
|
||||||
MapScriptToTypefaces["mtei"].Insert(0, "Noto Sans Meetei Mayek");
|
map["merc"].Insert(0, "Noto Sans Meroitic");
|
||||||
MapScriptToTypefaces["merc"].Insert(0, "Noto Sans Meroitic");
|
map["mero"].Insert(0, "Noto Sans Meroitic");
|
||||||
MapScriptToTypefaces["mero"].Insert(0, "Noto Sans Meroitic");
|
map["plrd"].Insert(0, "Noto Sans Miao");
|
||||||
MapScriptToTypefaces["plrd"].Insert(0, "Noto Sans Miao");
|
map["modi"].Insert(0, "Noto Sans Modi");
|
||||||
MapScriptToTypefaces["modi"].Insert(0, "Noto Sans Modi");
|
map["mong"].Insert(0, "Noto Sans Mongolian");
|
||||||
MapScriptToTypefaces["mong"].Insert(0, "Noto Sans Mongolian");
|
map["mroo"].Insert(0, "Noto Sans Mro");
|
||||||
MapScriptToTypefaces["mroo"].Insert(0, "Noto Sans Mro");
|
map["mult"].Insert(0, "Noto Sans Multani");
|
||||||
MapScriptToTypefaces["mult"].Insert(0, "Noto Sans Multani");
|
map["mymr"].Insert(0, "Noto Sans Myanmar");
|
||||||
MapScriptToTypefaces["mymr"].Insert(0, "Noto Sans Myanmar");
|
map["nkoo"].Insert(0, "Noto Sans Nko");
|
||||||
MapScriptToTypefaces["nkoo"].Insert(0, "Noto Sans Nko");
|
map["nbat"].Insert(0, "Noto Sans Nabataean");
|
||||||
MapScriptToTypefaces["nbat"].Insert(0, "Noto Sans Nabataean");
|
map["talu"].Insert(0, "Noto Sans New Tai Lue");
|
||||||
MapScriptToTypefaces["talu"].Insert(0, "Noto Sans New Tai Lue");
|
map["newa"].Insert(0, "Noto Sans Newa");
|
||||||
MapScriptToTypefaces["newa"].Insert(0, "Noto Sans Newa");
|
map["ogam"].Insert(0, "Noto Sans Ogham");
|
||||||
MapScriptToTypefaces["ogam"].Insert(0, "Noto Sans Ogham");
|
map["olck"].Insert(0, "Noto Sans Ol Chiki");
|
||||||
MapScriptToTypefaces["olck"].Insert(0, "Noto Sans Ol Chiki");
|
map["ital"].Insert(0, "Noto Sans Old Italian");
|
||||||
MapScriptToTypefaces["ital"].Insert(0, "Noto Sans Old Italian");
|
map["narb"].Insert(0, "Noto Sans Old North Arabian");
|
||||||
MapScriptToTypefaces["narb"].Insert(0, "Noto Sans Old North Arabian");
|
map["perm"].Insert(0, "Noto Sans Old Permic");
|
||||||
MapScriptToTypefaces["perm"].Insert(0, "Noto Sans Old Permic");
|
map["xpeo"].Insert(0, "Noto Sans Old Persian");
|
||||||
MapScriptToTypefaces["xpeo"].Insert(0, "Noto Sans Old Persian");
|
map["sarb"].Insert(0, "Noto Sans Old South Arabian");
|
||||||
MapScriptToTypefaces["sarb"].Insert(0, "Noto Sans Old South Arabian");
|
map["orkh"].Insert(0, "Noto Sans Old Turkic");
|
||||||
MapScriptToTypefaces["orkh"].Insert(0, "Noto Sans Old Turkic");
|
map["orya"].Insert(0, "Noto Sans Oriya");
|
||||||
MapScriptToTypefaces["orya"].Insert(0, "Noto Sans Oriya");
|
map["osge"].Insert(0, "Noto Sans Osage");
|
||||||
MapScriptToTypefaces["osge"].Insert(0, "Noto Sans Osage");
|
map["osma"].Insert(0, "Noto Sans Osmanya");
|
||||||
MapScriptToTypefaces["osma"].Insert(0, "Noto Sans Osmanya");
|
map["hmng"].Insert(0, "Noto Sans Pahawh Hmong");
|
||||||
MapScriptToTypefaces["hmng"].Insert(0, "Noto Sans Pahawh Hmong");
|
map["palm"].Insert(0, "Noto Sans Palmyrene");
|
||||||
MapScriptToTypefaces["palm"].Insert(0, "Noto Sans Palmyrene");
|
map["pauc"].Insert(0, "Noto Sans Pau Cin Hau");
|
||||||
MapScriptToTypefaces["pauc"].Insert(0, "Noto Sans Pau Cin Hau");
|
map["phag"].Insert(0, "Noto Sans Phags Pa");
|
||||||
MapScriptToTypefaces["phag"].Insert(0, "Noto Sans Phags Pa");
|
map["phnx"].Insert(0, "Noto Sans Phoenician");
|
||||||
MapScriptToTypefaces["phnx"].Insert(0, "Noto Sans Phoenician");
|
map["rjng"].Insert(0, "Noto Sans Rejang");
|
||||||
MapScriptToTypefaces["rjng"].Insert(0, "Noto Sans Rejang");
|
map["runr"].Insert(0, "Noto Sans Runic");
|
||||||
MapScriptToTypefaces["runr"].Insert(0, "Noto Sans Runic");
|
map["samr"].Insert(0, "Noto Sans Samaritan");
|
||||||
MapScriptToTypefaces["samr"].Insert(0, "Noto Sans Samaritan");
|
map["saur"].Insert(0, "Noto Sans Saurashtra");
|
||||||
MapScriptToTypefaces["saur"].Insert(0, "Noto Sans Saurashtra");
|
map["shrd"].Insert(0, "Noto Sans Sharada");
|
||||||
MapScriptToTypefaces["shrd"].Insert(0, "Noto Sans Sharada");
|
map["shaw"].Insert(0, "Noto Sans Shavian");
|
||||||
MapScriptToTypefaces["shaw"].Insert(0, "Noto Sans Shavian");
|
map["sinh"].Insert(0, "Noto Sans Sinhala");
|
||||||
MapScriptToTypefaces["sinh"].Insert(0, "Noto Sans Sinhala");
|
map["sora"].Insert(0, "Noto Sans Sora Sompeng");
|
||||||
MapScriptToTypefaces["sora"].Insert(0, "Noto Sans Sora Sompeng");
|
map["soyo"].Insert(0, "Noto Sans Soyombo");
|
||||||
MapScriptToTypefaces["soyo"].Insert(0, "Noto Sans Soyombo");
|
map["sund"].Insert(0, "Noto Sans Sundanese");
|
||||||
MapScriptToTypefaces["sund"].Insert(0, "Noto Sans Sundanese");
|
map["sylo"].Insert(0, "Noto Sans Syloti Nagri");
|
||||||
MapScriptToTypefaces["sylo"].Insert(0, "Noto Sans Syloti Nagri");
|
map["zsym"].Insert(0, "Noto Sans Symbols");
|
||||||
MapScriptToTypefaces["zsym"].Insert(0, "Noto Sans Symbols");
|
map["syrn"].Insert(0, "Noto Sans Syriac Eastern");
|
||||||
MapScriptToTypefaces["syrn"].Insert(0, "Noto Sans Syriac Eastern");
|
map["syre"].Insert(0, "Noto Sans Syriac Estrangela");
|
||||||
MapScriptToTypefaces["syre"].Insert(0, "Noto Sans Syriac Estrangela");
|
map["syrj"].Insert(0, "Noto Sans Syriac Western");
|
||||||
MapScriptToTypefaces["syrj"].Insert(0, "Noto Sans Syriac Western");
|
map["tglg"].Insert(0, "Noto Sans Tagalog");
|
||||||
MapScriptToTypefaces["tglg"].Insert(0, "Noto Sans Tagalog");
|
map["tagb"].Insert(0, "Noto Sans Tagbanwa");
|
||||||
MapScriptToTypefaces["tagb"].Insert(0, "Noto Sans Tagbanwa");
|
map["tale"].Insert(0, "Noto Sans Tai Le");
|
||||||
MapScriptToTypefaces["tale"].Insert(0, "Noto Sans Tai Le");
|
map["lana"].Insert(0, "Noto Sans Tai Tham");
|
||||||
MapScriptToTypefaces["lana"].Insert(0, "Noto Sans Tai Tham");
|
map["tavt"].Insert(0, "Noto Sans Tai Viet");
|
||||||
MapScriptToTypefaces["tavt"].Insert(0, "Noto Sans Tai Viet");
|
map["takr"].Insert(0, "Noto Sans Takri");
|
||||||
MapScriptToTypefaces["takr"].Insert(0, "Noto Sans Takri");
|
map["taml"].Insert(0, "Noto Sans Tamil");
|
||||||
MapScriptToTypefaces["taml"].Insert(0, "Noto Sans Tamil");
|
map["telu"].Insert(0, "Noto Sans Telugu");
|
||||||
MapScriptToTypefaces["telu"].Insert(0, "Noto Sans Telugu");
|
map["thaa"].Insert(0, "Noto Sans Thaana");
|
||||||
MapScriptToTypefaces["thaa"].Insert(0, "Noto Sans Thaana");
|
map["thai"].Insert(0, "Noto Sans Thai");
|
||||||
MapScriptToTypefaces["thai"].Insert(0, "Noto Sans Thai");
|
map["tfng"].Insert(0, "Noto Sans Tifinagh");
|
||||||
MapScriptToTypefaces["tfng"].Insert(0, "Noto Sans Tifinagh");
|
map["ugar"].Insert(0, "Noto Sans Ugaritic");
|
||||||
MapScriptToTypefaces["ugar"].Insert(0, "Noto Sans Ugaritic");
|
map["vaii"].Insert(0, "Noto Sans Vai");
|
||||||
MapScriptToTypefaces["vaii"].Insert(0, "Noto Sans Vai");
|
map["wcho"].Insert(0, "Noto Sans Wancho");
|
||||||
MapScriptToTypefaces["wcho"].Insert(0, "Noto Sans Wancho");
|
map["wara"].Insert(0, "Noto Sans Warang Citi");
|
||||||
MapScriptToTypefaces["wara"].Insert(0, "Noto Sans Warang Citi");
|
map["yiii"].Insert(0, "Noto Sans Yi");
|
||||||
MapScriptToTypefaces["yiii"].Insert(0, "Noto Sans Yi");
|
return map;
|
||||||
}
|
}
|
||||||
public FallbackListFontMatcher(FontManager manager) : base(manager) { }
|
public FallbackListFontMatcher(FontManager manager) : base(manager) { }
|
||||||
public override IEnumerable<Typeface> MatchScript(string script = null, bool distinctFamily = false) {
|
public override IEnumerable<Typeface> MatchScript(string script = null, bool distinctFamily = false) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
|
#pragma warning disable IDE0049
|
||||||
namespace Cryville.Common.Font {
|
namespace Cryville.Common.Font {
|
||||||
public abstract class FontTable<T> {
|
public abstract class FontTable<T> {
|
||||||
protected UInt32 Offset { get; private set; }
|
protected UInt32 Offset { get; private set; }
|
||||||
@@ -25,14 +26,17 @@ namespace Cryville.Common.Font {
|
|||||||
readonly UInt16 minorVersion;
|
readonly UInt16 minorVersion;
|
||||||
readonly UInt32 numFonts;
|
readonly UInt32 numFonts;
|
||||||
readonly List<UInt32> tableDirectoryOffsets = new List<UInt32>();
|
readonly List<UInt32> tableDirectoryOffsets = new List<UInt32>();
|
||||||
|
#pragma warning disable IDE0052 // Reserved
|
||||||
readonly String dsigTag;
|
readonly String dsigTag;
|
||||||
readonly UInt32 dsigLength;
|
readonly UInt32 dsigLength;
|
||||||
readonly UInt32 dsigOffset;
|
readonly UInt32 dsigOffset;
|
||||||
|
#pragma warning restore IDE0052 // Reserved
|
||||||
public TTCHeader(BinaryReader reader, UInt32 offset) : base(reader, offset) {
|
public TTCHeader(BinaryReader reader, UInt32 offset) : base(reader, offset) {
|
||||||
ttcTag = reader.ReadTag();
|
ttcTag = reader.ReadTag();
|
||||||
if (ttcTag != "ttcf") throw new NotImplementedException();
|
if (ttcTag != "ttcf") throw new NotSupportedException();
|
||||||
majorVersion = reader.ReadUInt16();
|
majorVersion = reader.ReadUInt16();
|
||||||
minorVersion = reader.ReadUInt16();
|
minorVersion = reader.ReadUInt16();
|
||||||
|
if (minorVersion != 0) throw new NotSupportedException();
|
||||||
numFonts = reader.ReadUInt32();
|
numFonts = reader.ReadUInt32();
|
||||||
for (UInt32 i = 0; i < numFonts; i++) tableDirectoryOffsets.Add(reader.ReadUInt32());
|
for (UInt32 i = 0; i < numFonts; i++) tableDirectoryOffsets.Add(reader.ReadUInt32());
|
||||||
if (majorVersion == 2) {
|
if (majorVersion == 2) {
|
||||||
@@ -52,12 +56,16 @@ namespace Cryville.Common.Font {
|
|||||||
public sealed class TableDirectory : FontTable<TableRecord, object> {
|
public sealed class TableDirectory : FontTable<TableRecord, object> {
|
||||||
readonly UInt32 sfntVersion;
|
readonly UInt32 sfntVersion;
|
||||||
readonly UInt16 numTables;
|
readonly UInt16 numTables;
|
||||||
|
#pragma warning disable IDE0052 // Reserved
|
||||||
readonly UInt16 searchRange;
|
readonly UInt16 searchRange;
|
||||||
readonly UInt16 entrySelector;
|
readonly UInt16 entrySelector;
|
||||||
readonly UInt16 rangeShift;
|
readonly UInt16 rangeShift;
|
||||||
|
#pragma warning restore IDE0052 // Reserved
|
||||||
readonly List<TableRecord> tableRecords = new List<TableRecord>();
|
readonly List<TableRecord> tableRecords = new List<TableRecord>();
|
||||||
public TableDirectory(BinaryReader reader, UInt32 offset) : base(reader, offset) {
|
public TableDirectory(BinaryReader reader, UInt32 offset) : base(reader, offset) {
|
||||||
sfntVersion = reader.ReadUInt32();
|
sfntVersion = reader.ReadUInt32();
|
||||||
|
if (sfntVersion != 0x00010000 && sfntVersion != 0x4F54544F &&
|
||||||
|
sfntVersion != 0x74727565 && sfntVersion != 0x74797031) throw new NotSupportedException();
|
||||||
numTables = reader.ReadUInt16();
|
numTables = reader.ReadUInt16();
|
||||||
searchRange = reader.ReadUInt16();
|
searchRange = reader.ReadUInt16();
|
||||||
entrySelector = reader.ReadUInt16();
|
entrySelector = reader.ReadUInt16();
|
||||||
@@ -99,48 +107,63 @@ namespace Cryville.Common.Font {
|
|||||||
count = reader.ReadUInt16();
|
count = reader.ReadUInt16();
|
||||||
storageOffset = reader.ReadUInt16();
|
storageOffset = reader.ReadUInt16();
|
||||||
for (UInt16 i = 0; i < count; i++)
|
for (UInt16 i = 0; i < count; i++)
|
||||||
nameRecord.Add(new NameRecord {
|
nameRecord.Add(new NameRecord(
|
||||||
platformID = reader.ReadUInt16(),
|
reader.ReadUInt16(),
|
||||||
encodingID = reader.ReadUInt16(),
|
reader.ReadUInt16(),
|
||||||
languageID = reader.ReadUInt16(),
|
reader.ReadUInt16(),
|
||||||
nameID = (NameID)reader.ReadUInt16(),
|
(NameID)reader.ReadUInt16(),
|
||||||
length = reader.ReadUInt16(),
|
reader.ReadUInt16(),
|
||||||
stringOffset = reader.ReadUInt16(),
|
reader.ReadUInt16()
|
||||||
});
|
));
|
||||||
if (version == 1) {
|
if (version == 1) {
|
||||||
langTagCount = reader.ReadUInt16();
|
langTagCount = reader.ReadUInt16();
|
||||||
for (UInt16 i = 0; i < langTagCount; i++)
|
for (UInt16 i = 0; i < langTagCount; i++)
|
||||||
langTagRecord.Add(new LangTagRecord {
|
langTagRecord.Add(new LangTagRecord(
|
||||||
length = reader.ReadUInt16(),
|
reader.ReadUInt16(),
|
||||||
langTagOffset = reader.ReadUInt16(),
|
reader.ReadUInt16()
|
||||||
});
|
));
|
||||||
|
}
|
||||||
|
foreach (var i in nameRecord)
|
||||||
|
i.Load(reader, offset + storageOffset);
|
||||||
|
if (version == 1) {
|
||||||
|
foreach (var i in langTagRecord)
|
||||||
|
i.Load(reader, offset + storageOffset);
|
||||||
}
|
}
|
||||||
UInt32 origin = (UInt32)reader.BaseStream.Position;
|
|
||||||
for (int i = 0; i < nameRecord.Count; i++) nameRecord[i] = nameRecord[i].Load(reader, origin);
|
|
||||||
for (int i = 0; i < langTagRecord.Count; i++) langTagRecord[i] = langTagRecord[i].Load(reader, origin);
|
|
||||||
}
|
}
|
||||||
public sealed override IReadOnlyList<NameRecord> GetItems() {
|
public sealed override IReadOnlyList<NameRecord> GetItems() {
|
||||||
return nameRecord;
|
return nameRecord;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public struct NameRecord {
|
public class NameRecord {
|
||||||
public UInt16 platformID;
|
public UInt16 PlatformID { get; private set; }
|
||||||
public UInt16 encodingID;
|
public UInt16 EncodingID { get; private set; }
|
||||||
public UInt16 languageID;
|
public UInt16 LanguageID { get; private set; }
|
||||||
public NameID nameID;
|
public NameID NameID { get; private set; }
|
||||||
public UInt16 length;
|
public UInt16 Length { get; private set; }
|
||||||
public UInt16 stringOffset;
|
public UInt16 StringOffset { get; private set; }
|
||||||
public String value { get; private set; }
|
public String Value { get; private set; }
|
||||||
public NameRecord Load(BinaryReader reader, UInt32 origin) {
|
public NameRecord(UInt16 platformID, UInt16 encodingID, UInt16 languageID, NameID nameID, UInt16 length, UInt16 stringOffset) {
|
||||||
reader.BaseStream.Position = origin + stringOffset;
|
PlatformID = platformID;
|
||||||
|
EncodingID = encodingID;
|
||||||
|
LanguageID = languageID;
|
||||||
|
NameID = nameID;
|
||||||
|
Length = length;
|
||||||
|
StringOffset = stringOffset;
|
||||||
|
}
|
||||||
|
public void Load(BinaryReader reader, UInt32 origin) {
|
||||||
|
reader.BaseStream.Position = origin + StringOffset;
|
||||||
Encoding encoding;
|
Encoding encoding;
|
||||||
switch (platformID) {
|
try {
|
||||||
case 0: encoding = Encoding.BigEndianUnicode; break;
|
switch (PlatformID) {
|
||||||
case 3: encoding = Encoding.BigEndianUnicode; break;
|
case 0: encoding = Encoding.BigEndianUnicode; break;
|
||||||
default: return this;
|
case 1: encoding = Encoding.GetEncoding(10000 + EncodingID); break;
|
||||||
|
case 3: encoding = Encoding.BigEndianUnicode; break;
|
||||||
|
default: return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
value = encoding.GetString(reader.ReadBytes(length));
|
catch (NotSupportedException) { return; }
|
||||||
return this;
|
catch (ArgumentException) { return; }
|
||||||
|
Value = encoding.GetString(reader.ReadBytes(Length));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public enum NameID : UInt16 {
|
public enum NameID : UInt16 {
|
||||||
@@ -171,47 +194,58 @@ namespace Cryville.Common.Font {
|
|||||||
DarkBackgroundPalette = 24,
|
DarkBackgroundPalette = 24,
|
||||||
VariationsPostScriptNamePrefix = 25,
|
VariationsPostScriptNamePrefix = 25,
|
||||||
}
|
}
|
||||||
public struct LangTagRecord {
|
public class LangTagRecord {
|
||||||
public UInt16 length;
|
public UInt16 Length { get; private set; }
|
||||||
public UInt16 langTagOffset;
|
public UInt16 LangTagOffset { get; private set; }
|
||||||
public String value { get; private set; }
|
public String Value { get; private set; }
|
||||||
public LangTagRecord Load(BinaryReader reader, UInt32 origin) {
|
public LangTagRecord(UInt16 length, UInt16 langTagOffset) {
|
||||||
reader.BaseStream.Position = origin + langTagOffset;
|
Length = length;
|
||||||
value = Encoding.BigEndianUnicode.GetString(reader.ReadBytes(length));
|
LangTagOffset = langTagOffset;
|
||||||
return this;
|
}
|
||||||
|
public void Load(BinaryReader reader, UInt32 origin) {
|
||||||
|
reader.BaseStream.Position = origin + LangTagOffset;
|
||||||
|
Value = Encoding.BigEndianUnicode.GetString(reader.ReadBytes(Length));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public sealed class MetaTable : FontTable<DataMap> {
|
public sealed class MetaTable : FontTable<DataMap> {
|
||||||
readonly UInt32 version;
|
readonly UInt32 version;
|
||||||
|
#pragma warning disable IDE0052 // Reserved
|
||||||
readonly UInt32 flags;
|
readonly UInt32 flags;
|
||||||
|
#pragma warning restore IDE0052 // Reserved
|
||||||
readonly UInt32 dataMapCount;
|
readonly UInt32 dataMapCount;
|
||||||
readonly List<DataMap> dataMaps = new List<DataMap>();
|
readonly List<DataMap> dataMaps = new List<DataMap>();
|
||||||
public MetaTable(BinaryReader reader, UInt32 offset) : base(reader, offset) {
|
public MetaTable(BinaryReader reader, UInt32 offset) : base(reader, offset) {
|
||||||
version = reader.ReadUInt32();
|
version = reader.ReadUInt32();
|
||||||
|
if (version != 1) throw new NotSupportedException();
|
||||||
flags = reader.ReadUInt32();
|
flags = reader.ReadUInt32();
|
||||||
reader.ReadUInt32();
|
reader.ReadUInt32();
|
||||||
dataMapCount = reader.ReadUInt32();
|
dataMapCount = reader.ReadUInt32();
|
||||||
for (UInt32 i = 0; i < dataMapCount; i++)
|
for (UInt32 i = 0; i < dataMapCount; i++)
|
||||||
dataMaps.Add(new DataMap {
|
dataMaps.Add(new DataMap (
|
||||||
tag = reader.ReadTag(),
|
reader.ReadTag(),
|
||||||
dataOffset = reader.ReadUInt32(),
|
reader.ReadUInt32(),
|
||||||
dataLength = reader.ReadUInt32(),
|
reader.ReadUInt32()
|
||||||
});
|
));
|
||||||
for (int i = 0; i < dataMaps.Count; i++) dataMaps[i] = dataMaps[i].Load(reader, offset);
|
foreach (var i in dataMaps)
|
||||||
|
i.Load(reader, offset);
|
||||||
}
|
}
|
||||||
public sealed override IReadOnlyList<DataMap> GetItems() {
|
public sealed override IReadOnlyList<DataMap> GetItems() {
|
||||||
return dataMaps;
|
return dataMaps;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public struct DataMap {
|
public class DataMap {
|
||||||
public String tag;
|
public String Tag { get; private set; }
|
||||||
public UInt32 dataOffset;
|
public UInt32 DataOffset { get; private set; }
|
||||||
public UInt32 dataLength;
|
public UInt32 DataLength { get; private set; }
|
||||||
public String value { get; private set; }
|
public String Value { get; private set; }
|
||||||
public DataMap Load(BinaryReader reader, UInt32 origin) {
|
public DataMap(String tag, UInt32 dataOffset, UInt32 dataLength) {
|
||||||
reader.BaseStream.Position = origin + dataOffset;
|
Tag = tag;
|
||||||
value = Encoding.ASCII.GetString(reader.ReadBytes((int)dataLength));
|
DataOffset = dataOffset;
|
||||||
return this;
|
DataLength = dataLength;
|
||||||
|
}
|
||||||
|
public void Load(BinaryReader reader, UInt32 origin) {
|
||||||
|
reader.BaseStream.Position = origin + DataOffset;
|
||||||
|
Value = Encoding.ASCII.GetString(reader.ReadBytes((int)DataLength));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class BinaryReaderExtensions {
|
public static class BinaryReaderExtensions {
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ namespace Cryville.Common.Font {
|
|||||||
protected override void GetName(BinaryReader reader) {
|
protected override void GetName(BinaryReader reader) {
|
||||||
var dir = new TableDirectory(reader, (uint)reader.BaseStream.Position);
|
var dir = new TableDirectory(reader, (uint)reader.BaseStream.Position);
|
||||||
var nameTable = (NameTable)dir.GetSubTable((from i in dir.GetItems() where i.tableTag == "name" select i).Single());
|
var nameTable = (NameTable)dir.GetSubTable((from i in dir.GetItems() where i.tableTag == "name" select i).Single());
|
||||||
FamilyName = (from i in nameTable.GetItems() where i.nameID == NameID.FontFamilyName && i.value != null select i.value).First();
|
FamilyName = (from i in nameTable.GetItems() where i.NameID == NameID.FontFamilyName && i.Value != null select i.Value).First();
|
||||||
SubfamilyName = (from i in nameTable.GetItems() where i.nameID == NameID.FontSubfamilyName && i.value != null select i.value).First();
|
SubfamilyName = (from i in nameTable.GetItems() where i.NameID == NameID.FontSubfamilyName && i.Value != null select i.Value).First();
|
||||||
FullName = (from i in nameTable.GetItems() where i.nameID == NameID.FullFontName && i.value != null select i.value).First();
|
FullName = (from i in nameTable.GetItems() where i.NameID == NameID.FullFontName && i.Value != null select i.Value).First();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
8
Assets/Cryville/Common/Network/Http11.meta
Normal file
8
Assets/Cryville/Common/Network/Http11.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1a624371d4108614b9cdc4acca1499e2
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -4,12 +4,11 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Cryville.Common.Network {
|
namespace Cryville.Common.Network.Http11 {
|
||||||
public class HttpClient {
|
public class Http11Client : IDisposable {
|
||||||
private readonly string _directHost;
|
private readonly string _directHost;
|
||||||
protected string DirectHost { get { return _directHost; } }
|
protected string DirectHost { get { return _directHost; } }
|
||||||
|
|
||||||
@@ -19,29 +18,17 @@ namespace Cryville.Common.Network {
|
|||||||
readonly Uri _baseUri;
|
readonly Uri _baseUri;
|
||||||
readonly int origPort;
|
readonly int origPort;
|
||||||
|
|
||||||
protected string Version = "HTTP/1.1";
|
protected const string Version = "HTTP/1.1";
|
||||||
protected TcpClient TcpClient { get; private set; }
|
protected TcpClient TcpClient { get; private set; }
|
||||||
protected Stream RawTcpStream {
|
protected Stream RawTcpStream { get { return TcpClient.GetStream(); } }
|
||||||
get {
|
protected virtual Stream Stream { get { return TcpClient.GetStream(); } }
|
||||||
return TcpClient.GetStream();
|
protected virtual string WindowsProxyProtocolName { get { return "http"; } }
|
||||||
}
|
|
||||||
}
|
|
||||||
protected virtual Stream Stream {
|
|
||||||
get {
|
|
||||||
return TcpClient.GetStream();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
protected virtual string WindowsProxyProtocolName {
|
|
||||||
get {
|
|
||||||
return "http";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly bool _proxied = false;
|
private readonly bool _proxied = false;
|
||||||
|
|
||||||
public Dictionary<string, string> Headers { get; set; }
|
public Dictionary<string, string> Headers { get; set; }
|
||||||
|
|
||||||
public HttpClient(Uri baseUri, int port = 80) {
|
public Http11Client(Uri baseUri, int port = 80) {
|
||||||
_directHost = baseUri.Host;
|
_directHost = baseUri.Host;
|
||||||
_directPort = port;
|
_directPort = port;
|
||||||
_baseUri = baseUri;
|
_baseUri = baseUri;
|
||||||
@@ -61,18 +48,29 @@ namespace Cryville.Common.Network {
|
|||||||
public virtual void Close() {
|
public virtual void Close() {
|
||||||
TcpClient.Close();
|
TcpClient.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpResponse Request(string method, Uri uri, string body = null, Encoding encoding = null) {
|
public void Dispose() {
|
||||||
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void Dispose(bool disposing) {
|
||||||
|
if (disposing) {
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Http11Response Request(string method, Uri uri, string body = null, Encoding encoding = null) {
|
||||||
string struri = GetUri(uri).PathAndQuery;
|
string struri = GetUri(uri).PathAndQuery;
|
||||||
return Request(Stream, method, struri, body, encoding);
|
return Request(Stream, method, struri, body, encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpResponse Request(Stream stream, string method, string uri, string body = null, Encoding encoding = null) {
|
Http11Response Request(Stream stream, string method, string uri, string body = null, Encoding encoding = null) {
|
||||||
var headers = new Dictionary<string, string>();
|
var headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||||
foreach (var h in Headers)
|
foreach (var h in Headers)
|
||||||
headers.Add(h.Key, h.Value);
|
headers.Add(h.Key, h.Value);
|
||||||
headers["Host"] = _baseUri.Host;
|
headers["Host"] = _baseUri.Host;
|
||||||
byte[] payload = new byte[0];
|
byte[] payload = null;
|
||||||
if (body != null) {
|
if (body != null) {
|
||||||
if (encoding == null)
|
if (encoding == null)
|
||||||
encoding = Encoding.UTF8;
|
encoding = Encoding.UTF8;
|
||||||
@@ -80,22 +78,24 @@ namespace Cryville.Common.Network {
|
|||||||
headers.Add("Content-Encoding", encoding.EncodingName);
|
headers.Add("Content-Encoding", encoding.EncodingName);
|
||||||
headers.Add("Content-Length", payload.Length.ToString(CultureInfo.InvariantCulture));
|
headers.Add("Content-Length", payload.Length.ToString(CultureInfo.InvariantCulture));
|
||||||
}
|
}
|
||||||
string request_line = string.Format(
|
using (var writer = new StreamWriter(stream, Encoding.ASCII, 1024, true)) {
|
||||||
"{0} {1} {2}\r\n", method, uri, Version
|
writer.Write(method);
|
||||||
);
|
writer.Write(' ');
|
||||||
string header_fields = string.Concat((
|
writer.Write(uri);
|
||||||
from h in headers select h.Key + ":" + h.Value + "\r\n"
|
writer.Write(' ');
|
||||||
).ToArray());
|
writer.Write(Version);
|
||||||
byte[] buffer0 = Encoding.ASCII.GetBytes(string.Format(
|
writer.Write("\r\n");
|
||||||
"{0}{1}\r\n", request_line, header_fields
|
foreach (var header in headers) {
|
||||||
));
|
writer.Write(header.Key);
|
||||||
byte[] buffer1 = new byte[buffer0.Length + payload.Length];
|
writer.Write(':');
|
||||||
Array.Copy(buffer0, buffer1, buffer0.Length);
|
writer.Write(header.Value);
|
||||||
Array.Copy(payload, 0, buffer1, buffer0.Length, payload.Length);
|
writer.Write("\r\n");
|
||||||
Logger.Log("main", 0, "Network", Encoding.UTF8.GetString(buffer1));
|
}
|
||||||
stream.Write(buffer1, 0, buffer1.Length);
|
writer.Write("\r\n");
|
||||||
stream.Flush();
|
if (payload != null) writer.Write(payload);
|
||||||
var response = new HttpResponse(stream);
|
writer.Flush();
|
||||||
|
}
|
||||||
|
var response = new Http11Response(stream);
|
||||||
Logger.Log("main", 0, "Network", "{0}", response);
|
Logger.Log("main", 0, "Network", "{0}", response);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 9653d5e145f2866439a0fcd1b27f49c4
|
guid: 5a795e416e54c69418de1a3c27a88932
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
@@ -1,31 +1,41 @@
|
|||||||
using Cryville.Common.Logging;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Cryville.Common.Network {
|
namespace Cryville.Common.Network.Http11 {
|
||||||
public class HttpResponse {
|
public class Http11Response : IDisposable {
|
||||||
static readonly char[] spchar = new char[]{ ' ' };
|
static readonly char[] spchar = new char[]{ ' ' };
|
||||||
public string HttpVersion { get; private set; }
|
public string HttpVersion { get; private set; }
|
||||||
public string StatusCode { get; private set; }
|
public string StatusCode { get; private set; }
|
||||||
public string ReasonPhase { get; private set; }
|
public string ReasonPhase { get; private set; }
|
||||||
public Dictionary<string, string> Headers { get; private set; }
|
public Dictionary<string, string> Headers { get; private set; }
|
||||||
public HttpResponseStream MessageBody { get; private set; }
|
public Http11ResponseStream MessageBody { get; private set; }
|
||||||
internal HttpResponse(Stream stream) {
|
internal Http11Response(Stream stream) {
|
||||||
var reader = new BinaryReader(stream, Encoding.ASCII);
|
var reader = new BinaryReader(stream, Encoding.ASCII);
|
||||||
var statu_line = ReadLine(reader).Split(spchar, 3);
|
var statu_line = ReadLine(reader).Split(spchar, 3);
|
||||||
HttpVersion = statu_line[0];
|
HttpVersion = statu_line[0];
|
||||||
StatusCode = statu_line[1];
|
StatusCode = statu_line[1];
|
||||||
ReasonPhase = statu_line[2];
|
ReasonPhase = statu_line[2];
|
||||||
Logger.Log("main", 0, "Network", "Receive Response: {0} {1} {2}", HttpVersion, StatusCode, ReasonPhase);
|
Headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||||
Headers = new Dictionary<string, string>();
|
|
||||||
while (ParseHeader(reader, Headers)) ;
|
while (ParseHeader(reader, Headers)) ;
|
||||||
if (Headers.ContainsKey("content-length")) {
|
if (Headers.ContainsKey("content-length")) {
|
||||||
int length = int.Parse(Headers["content-length"]);
|
int length = int.Parse(Headers["content-length"]);
|
||||||
MessageBody = new HttpResponseBlockStream(reader, length);
|
MessageBody = new Http11ResponseBlockStream(reader, length);
|
||||||
}
|
}
|
||||||
else if (Headers.ContainsKey("transfer-encoding") && Headers["transfer-encoding"] == "chunked") {
|
else if (Headers.ContainsKey("transfer-encoding") && Headers["transfer-encoding"] == "chunked") {
|
||||||
MessageBody = new HttpResponseChunkedStream(reader);
|
MessageBody = new Http11ResponseChunkedStream(reader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose() {
|
||||||
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void Dispose(bool disposing) {
|
||||||
|
if (disposing) {
|
||||||
|
MessageBody.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,12 +47,11 @@ namespace Cryville.Common.Network {
|
|||||||
// TODO Multiline header
|
// TODO Multiline header
|
||||||
var header = ReadLine(reader);
|
var header = ReadLine(reader);
|
||||||
if (header == "") return false;
|
if (header == "") return false;
|
||||||
var s = header.Split(':');
|
var s = header.Split(':', 2);
|
||||||
string field_name = s[0].Trim().ToLower();
|
string field_name = s[0].Trim().ToLower();
|
||||||
string field_value = s[1].Trim();
|
string field_value = s[1].Trim();
|
||||||
if (headers.ContainsKey(field_name)) headers[field_name] += "," + field_value;
|
if (headers.ContainsKey(field_name)) headers[field_name] += "," + field_value;
|
||||||
else headers.Add(field_name, field_value);
|
else headers.Add(field_name, field_value);
|
||||||
Logger.Log("main", 0, "Network", "Receive Header {0}: {1}", field_name, field_value);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
11
Assets/Cryville/Common/Network/Http11/Http11Response.cs.meta
Normal file
11
Assets/Cryville/Common/Network/Http11/Http11Response.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 71234dd1c93d47b4893750686b2333a3
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
using Cryville.Common.Logging;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Cryville.Common.Network {
|
namespace Cryville.Common.Network.Http11 {
|
||||||
public abstract class HttpResponseStream : Stream {
|
public abstract class Http11ResponseStream : Stream {
|
||||||
public override bool CanRead { get { return true; } }
|
public override bool CanRead { get { return true; } }
|
||||||
|
|
||||||
public override bool CanSeek { get { return false; } }
|
public override bool CanSeek { get { return false; } }
|
||||||
@@ -37,11 +36,11 @@ namespace Cryville.Common.Network {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal sealed class HttpResponseBlockStream : HttpResponseStream {
|
internal sealed class Http11ResponseBlockStream : Http11ResponseStream {
|
||||||
readonly BinaryReader _reader;
|
readonly BinaryReader _reader;
|
||||||
readonly int _length;
|
readonly int _length;
|
||||||
int _pos = 0;
|
int _pos = 0;
|
||||||
internal HttpResponseBlockStream(BinaryReader reader, int length) {
|
internal Http11ResponseBlockStream(BinaryReader reader, int length) {
|
||||||
_reader = reader;
|
_reader = reader;
|
||||||
_length = length;
|
_length = length;
|
||||||
}
|
}
|
||||||
@@ -51,7 +50,6 @@ namespace Cryville.Common.Network {
|
|||||||
if (recv_len == 0) return 0;
|
if (recv_len == 0) return 0;
|
||||||
while (recv < recv_len) {
|
while (recv < recv_len) {
|
||||||
recv += _reader.Read(buffer, offset + recv, count - recv);
|
recv += _reader.Read(buffer, offset + recv, count - recv);
|
||||||
Logger.Log("main", 0, "Network", "Message body received: {0}/{1}/{2}", recv, recv_len, _length);
|
|
||||||
}
|
}
|
||||||
_pos += recv_len;
|
_pos += recv_len;
|
||||||
return recv_len;
|
return recv_len;
|
||||||
@@ -63,36 +61,34 @@ namespace Cryville.Common.Network {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal sealed class HttpResponseChunkedStream : HttpResponseStream {
|
internal sealed class Http11ResponseChunkedStream : Http11ResponseStream {
|
||||||
readonly BinaryReader _reader;
|
readonly BinaryReader _reader;
|
||||||
byte[] _chunk = null;
|
byte[] _chunk = null;
|
||||||
int _pos = 0;
|
int _pos = 0;
|
||||||
internal HttpResponseChunkedStream(BinaryReader reader) {
|
internal Http11ResponseChunkedStream(BinaryReader reader) {
|
||||||
_reader = reader;
|
_reader = reader;
|
||||||
ReadChunk();
|
ReadChunk();
|
||||||
}
|
}
|
||||||
public void ReadChunk() {
|
public void ReadChunk() {
|
||||||
if (_chunk != null && _chunk.Length == 0) return;
|
if (_chunk != null && _chunk.Length == 0) return;
|
||||||
string[] chunkHeader = HttpResponse.ReadLine(_reader).Split(';');
|
string[] chunkHeader = Http11Response.ReadLine(_reader).Split(';');
|
||||||
// int chunkSize = Array.IndexOf(LEN, chunkHeader[0].ToLower()[0]);
|
int chunkSize;
|
||||||
int chunkSize = int.Parse(chunkHeader[0], NumberStyles.HexNumber);
|
if (!int.TryParse(chunkHeader[0], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out chunkSize))
|
||||||
if (chunkSize == -1)
|
|
||||||
throw new IOException("Corrupted chunk received");
|
throw new IOException("Corrupted chunk received");
|
||||||
if (chunkSize == 0) {
|
if (chunkSize == 0) {
|
||||||
_chunk = new byte[0];
|
_chunk = new byte[0];
|
||||||
// TODO TE Header, now just discard
|
// TODO TE Header, now just discard
|
||||||
var headers = new Dictionary<string, string>();
|
var headers = new Dictionary<string, string>();
|
||||||
while (HttpResponse.ParseHeader(_reader, headers)) ;
|
while (Http11Response.ParseHeader(_reader, headers)) ;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_chunk = new byte[chunkSize];
|
_chunk = new byte[chunkSize];
|
||||||
int recv = 0;
|
int recv = 0;
|
||||||
while (recv < chunkSize) {
|
while (recv < chunkSize) {
|
||||||
recv += _reader.Read(_chunk, recv, chunkSize - recv);
|
recv += _reader.Read(_chunk, recv, chunkSize - recv);
|
||||||
Logger.Log("main", 0, "Network", "Message chunk received: {0}/{1}", recv, chunkSize);
|
|
||||||
}
|
}
|
||||||
_pos = 0;
|
_pos = 0;
|
||||||
if (HttpResponse.ReadLine(_reader) != "")
|
if (Http11Response.ReadLine(_reader) != "")
|
||||||
throw new IOException("Corrupted chunk received");
|
throw new IOException("Corrupted chunk received");
|
||||||
}
|
}
|
||||||
public override int Read(byte[] buffer, int offset, int count) {
|
public override int Read(byte[] buffer, int offset, int count) {
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 49a8d5b9869e5bb42bafbe71f84fecc5
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace Cryville.Common.Network {
|
namespace Cryville.Common.Network.Http11 {
|
||||||
public class HttpsClient : HttpClient {
|
public class Https11Client : Http11Client {
|
||||||
readonly TlsClient _tlsClient;
|
readonly TlsClient _tlsClient;
|
||||||
|
|
||||||
protected override Stream Stream {
|
protected override Stream Stream {
|
||||||
@@ -16,7 +16,7 @@ namespace Cryville.Common.Network {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpsClient(Uri baseUri) : base(baseUri, 443) {
|
public Https11Client(Uri baseUri) : base(baseUri, 443) {
|
||||||
_tlsClient = new TlsClient(RawTcpStream, baseUri.Host);
|
_tlsClient = new TlsClient(RawTcpStream, baseUri.Host);
|
||||||
}
|
}
|
||||||
|
|
||||||
11
Assets/Cryville/Common/Network/Http11/Https11Client.cs.meta
Normal file
11
Assets/Cryville/Common/Network/Http11/Https11Client.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c5c233e6228ce204fa1a9724c48ac8fe
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 5ea931bf5488011468f3d1243a038874
|
|
||||||
timeCreated: 1622589817
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 07e8215a93e3eb1418685009f0c58dcd
|
|
||||||
timeCreated: 1622596274
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: f191de447a708da4f9d230e6545ce0a6
|
|
||||||
timeCreated: 1635470462
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 9b35290e0e147a342acc29a20c8fceaf
|
|
||||||
timeCreated: 1622503538
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
using Cryville.Common.Logging;
|
|
||||||
using Org.BouncyCastle.Security;
|
using Org.BouncyCastle.Security;
|
||||||
using Org.BouncyCastle.Tls;
|
using Org.BouncyCastle.Tls;
|
||||||
using Org.BouncyCastle.Tls.Crypto;
|
using Org.BouncyCastle.Tls.Crypto;
|
||||||
using Org.BouncyCastle.Tls.Crypto.Impl.BC;
|
using Org.BouncyCastle.Tls.Crypto.Impl.BC;
|
||||||
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -10,7 +10,7 @@ using System.Text;
|
|||||||
using BcTlsClient = Org.BouncyCastle.Tls.TlsClient;
|
using BcTlsClient = Org.BouncyCastle.Tls.TlsClient;
|
||||||
|
|
||||||
namespace Cryville.Common.Network {
|
namespace Cryville.Common.Network {
|
||||||
public class TlsClient {
|
public class TlsClient : IDisposable {
|
||||||
readonly TlsClientProtocol _protocol;
|
readonly TlsClientProtocol _protocol;
|
||||||
readonly BcTlsClient _tlsClient;
|
readonly BcTlsClient _tlsClient;
|
||||||
public Stream Stream { get; private set; }
|
public Stream Stream { get; private set; }
|
||||||
@@ -28,6 +28,17 @@ namespace Cryville.Common.Network {
|
|||||||
_protocol.Close();
|
_protocol.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose() {
|
||||||
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void Dispose(bool disposing) {
|
||||||
|
if (disposing) {
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class InternalTlsClient : DefaultTlsClient {
|
private class InternalTlsClient : DefaultTlsClient {
|
||||||
readonly string _host;
|
readonly string _host;
|
||||||
|
|
||||||
@@ -72,20 +83,6 @@ namespace Cryville.Common.Network {
|
|||||||
public override TlsAuthentication GetAuthentication() {
|
public override TlsAuthentication GetAuthentication() {
|
||||||
return new NullTlsAuthentication();
|
return new NullTlsAuthentication();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void NotifyAlertReceived(short alertLevel, short alertDescription) {
|
|
||||||
Logger.Log("main", 0, "Network/TLS", "TLS Alert {0} {1}", alertLevel, alertDescription);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void NotifyServerVersion(ProtocolVersion serverVersion) {
|
|
||||||
base.NotifyServerVersion(serverVersion);
|
|
||||||
Logger.Log("main", 0, "Network/TLS", "NotifyServerVersion {0}", serverVersion);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void NotifySelectedCipherSuite(int selectedCipherSuite) {
|
|
||||||
base.NotifySelectedCipherSuite(selectedCipherSuite);
|
|
||||||
Logger.Log("main", 0, "Network/TLS", "NotifySelectedCipherSuite {0}", selectedCipherSuite);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class NullTlsAuthentication : TlsAuthentication {
|
private class NullTlsAuthentication : TlsAuthentication {
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// <param name="exp">The expression to evaluate.</param>
|
/// <param name="exp">The expression to evaluate.</param>
|
||||||
/// <returns>Whether the evaluaton succeeded.</returns>
|
/// <returns>Whether the evaluaton succeeded.</returns>
|
||||||
public bool Evaluate(PdtOperator target, PdtExpression exp) {
|
public bool Evaluate(PdtOperator target, PdtExpression exp) {
|
||||||
|
var prevFrameCount = _framecount;
|
||||||
try {
|
try {
|
||||||
var prevFrameCount = _framecount;
|
|
||||||
_revokepttconst = false;
|
_revokepttconst = false;
|
||||||
for (var ip = exp.Instructions.First; ip != null; ip = ip.Next)
|
for (var ip = exp.Instructions.First; ip != null; ip = ip.Next)
|
||||||
ip.Value.Execute(this, ref ip);
|
ip.Value.Execute(this, ref ip);
|
||||||
@@ -33,12 +33,14 @@ namespace Cryville.Common.Pdt {
|
|||||||
exp.IsConstant = exp.IsPotentialConstant = !_revokepttconst;
|
exp.IsConstant = exp.IsPotentialConstant = !_revokepttconst;
|
||||||
}
|
}
|
||||||
var ret = Operate(target, _framecount - prevFrameCount, true);
|
var ret = Operate(target, _framecount - prevFrameCount, true);
|
||||||
for (var i = prevFrameCount; i < _framecount; i++) DiscardStack();
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
throw new EvaluationFailureException(exp, ex);
|
throw new EvaluationFailureException(exp, ex);
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
for (var i = prevFrameCount; i < _framecount; i++) DiscardStack();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Optimizes an expression by merging its instructions.
|
/// Optimizes an expression by merging its instructions.
|
||||||
@@ -133,10 +135,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
for (var ins = il.First; ins != null; ins = ins.Next) {
|
for (var ins = il.First; ins != null; ins = ins.Next) {
|
||||||
if (!(ins.Value is PdtInstruction.PushConstant)) {
|
if (!(ins.Value is PdtInstruction.PushConstant)) {
|
||||||
exp.IsConstant = false;
|
exp.IsConstant = false;
|
||||||
}
|
break;
|
||||||
else if (!(ins.Value is PdtInstruction.PushVariable)) {
|
|
||||||
exp.IsPotentialConstant = false;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -205,7 +204,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
var frame = _stack[--_framecount];
|
var frame = _stack[--_framecount];
|
||||||
if (frame.Type == PdtInternalType.Error) {
|
if (frame.Type == PdtInternalType.Error) {
|
||||||
_framecount -= pc - i - 1;
|
_framecount -= pc - i - 1;
|
||||||
_stack[_framecount++] = new StackFrame { Type = PdtInternalType.Error, Offset = _goffset, Length = 0 };
|
_stack[_framecount++] = new StackFrame { Type = PdtInternalType.Error, Offset = -1, Length = 0 };
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
op.LoadOperand(new PdtVariableMemory(frame.Type, pmem + frame.Offset, frame.Length));
|
op.LoadOperand(new PdtVariableMemory(frame.Type, pmem + frame.Offset, frame.Length));
|
||||||
@@ -218,13 +217,15 @@ namespace Cryville.Common.Pdt {
|
|||||||
internal unsafe void Collapse(int name, ref LinkedListNode<PdtInstruction> self, LinkedListNode<PdtInstruction> target) {
|
internal unsafe void Collapse(int name, ref LinkedListNode<PdtInstruction> self, LinkedListNode<PdtInstruction> target) {
|
||||||
fixed (byte* pmem = _mem) {
|
fixed (byte* pmem = _mem) {
|
||||||
var frame = _stack[--_framecount];
|
var frame = _stack[--_framecount];
|
||||||
|
_goffset -= frame.Length;
|
||||||
if (frame.Type == PdtInternalType.Error) {
|
if (frame.Type == PdtInternalType.Error) {
|
||||||
_stack[_framecount++] = new StackFrame { Type = PdtInternalType.Error, Offset = _goffset, Length = 0 };
|
_stack[_framecount++] = new StackFrame { Type = PdtInternalType.Error, Offset = -1, Length = 0 };
|
||||||
self = target;
|
self = target;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Collapse(name, new PdtVariableMemory(frame.Type, pmem + frame.Offset, frame.Length))) {
|
if (Collapse(name, new PdtVariableMemory(frame.Type, pmem + frame.Offset, frame.Length))) {
|
||||||
_framecount++;
|
_framecount++;
|
||||||
|
_goffset += frame.Length;
|
||||||
self = target;
|
self = target;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ namespace Cryville.Common.Unity {
|
|||||||
suspended = true;
|
suspended = true;
|
||||||
if (currentNetworkTask != null) {
|
if (currentNetworkTask != null) {
|
||||||
currentNetworkTask.Cancel();
|
currentNetworkTask.Cancel();
|
||||||
|
networkTasks.Enqueue(currentNetworkTask);
|
||||||
currentNetworkTask = null;
|
currentNetworkTask = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -91,15 +92,6 @@ namespace Cryville.Common.Unity {
|
|||||||
/// A network task.
|
/// A network task.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class NetworkTask {
|
public abstract class NetworkTask {
|
||||||
protected NetworkTask(string uri) {
|
|
||||||
Uri = uri;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The URI of the resource.
|
|
||||||
/// </summary>
|
|
||||||
public string Uri { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether the task is cancelled.
|
/// Whether the task is cancelled.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -108,40 +100,56 @@ namespace Cryville.Common.Unity {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Cancels the task.
|
/// Cancels the task.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void Cancel() {
|
public void Cancel() {
|
||||||
Cancelled = true;
|
Cancelled = true;
|
||||||
|
OnCancel();
|
||||||
}
|
}
|
||||||
|
protected virtual void OnCancel() { }
|
||||||
|
|
||||||
#if UNITY_5_4_OR_NEWER
|
|
||||||
protected UnityWebRequest www;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Starts the task.
|
/// Starts the task.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void Start() {
|
public abstract void Start();
|
||||||
www = new UnityWebRequest(Uri);
|
|
||||||
www.SendWebRequest();
|
|
||||||
}
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets whether the task is done.
|
/// Gets whether the task is done.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Whether the task is done.</returns>
|
/// <returns>Whether the task is done.</returns>
|
||||||
public virtual bool Done() {
|
public abstract bool Done();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A Unity network task.
|
||||||
|
/// </summary>
|
||||||
|
public abstract class UnityNetworkTask : NetworkTask {
|
||||||
|
protected UnityNetworkTask(string uri) {
|
||||||
|
Uri = uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The URI of the resource.
|
||||||
|
/// </summary>
|
||||||
|
public string Uri { get; private set; }
|
||||||
|
|
||||||
|
#if UNITY_5_4_OR_NEWER
|
||||||
|
protected UnityWebRequest www;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override void Start() {
|
||||||
|
www = new UnityWebRequest(Uri);
|
||||||
|
www.SendWebRequest();
|
||||||
|
}
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override bool Done() {
|
||||||
if (!www.isDone) return false;
|
if (!www.isDone) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
protected WWW www;
|
protected WWW www;
|
||||||
/// <summary>
|
/// <inheritdoc />
|
||||||
/// Starts the task.
|
|
||||||
/// </summary>
|
|
||||||
public virtual void Start() {
|
public virtual void Start() {
|
||||||
www = new WWW(Uri);
|
www = new WWW(Uri);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <inheritdoc />
|
||||||
/// Gets whether the task is done.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Whether the task is done.</returns>
|
|
||||||
public virtual bool Done() {
|
public virtual bool Done() {
|
||||||
if (!www.isDone) return false;
|
if (!www.isDone) return false;
|
||||||
return true;
|
return true;
|
||||||
@@ -149,9 +157,9 @@ namespace Cryville.Common.Unity {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A <see cref="NetworkTask" /> that loads a texture.
|
/// A <see cref="UnityNetworkTask" /> that loads a texture.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class LoadTextureTask : NetworkTask {
|
public class LoadTextureTask : UnityNetworkTask {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates an instance of the <see cref="LoadTextureTask" /> class.
|
/// Creates an instance of the <see cref="LoadTextureTask" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
50
Assets/Cryville/Common/Unity/ScopedThreadAttacherInjector.cs
Normal file
50
Assets/Cryville/Common/Unity/ScopedThreadAttacherInjector.cs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#if UNITY_EDITOR
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using UnityEditor;
|
||||||
|
|
||||||
|
namespace Cryville.Common.Unity {
|
||||||
|
[InitializeOnLoad]
|
||||||
|
public class ScopedThreadAttacherInjector {
|
||||||
|
static readonly Encoding _encoding = new UTF8Encoding(false, true);
|
||||||
|
static string _filePath;
|
||||||
|
static string _oldSrc;
|
||||||
|
|
||||||
|
static ScopedThreadAttacherInjector() {
|
||||||
|
BuildPlayerWindow.RegisterBuildPlayerHandler(opt => HandlePlayerBuild(opt));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void HandlePlayerBuild(BuildPlayerOptions opt) {
|
||||||
|
try {
|
||||||
|
OnPreprocessBuild();
|
||||||
|
BuildPlayerWindow.DefaultBuildMethods.BuildPlayer(opt);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
OnPostprocessBuild();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void OnPreprocessBuild() {
|
||||||
|
var il2cppRoot = Environment.GetEnvironmentVariable("UNITY_IL2CPP_PATH");
|
||||||
|
if (string.IsNullOrEmpty(il2cppRoot)) {
|
||||||
|
_filePath = string.Empty;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_filePath = Path.Combine(il2cppRoot, "libil2cpp", "vm", "ScopedThreadAttacher.cpp");
|
||||||
|
if (!File.Exists(_filePath)) {
|
||||||
|
_filePath = string.Empty;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_oldSrc = File.ReadAllText(_filePath, _encoding);
|
||||||
|
File.WriteAllText(_filePath, Regex.Replace(_oldSrc, @"~\s*?ScopedThreadAttacher\s*?\(\s*?\)\s*?\{.*\}", "~ScopedThreadAttacher(){}", RegexOptions.Singleline), _encoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void OnPostprocessBuild() {
|
||||||
|
if (string.IsNullOrEmpty(_filePath)) return;
|
||||||
|
File.WriteAllText(_filePath, _oldSrc, _encoding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2322d8e9250e9e6469826361223dfdda
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -6,6 +6,7 @@ using TMPro;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.TextCore.LowLevel;
|
using UnityEngine.TextCore.LowLevel;
|
||||||
using UnityEngine.TextCore.Text;
|
using UnityEngine.TextCore.Text;
|
||||||
|
using Logger = Cryville.Common.Logging.Logger;
|
||||||
|
|
||||||
namespace Cryville.Common.Unity.UI {
|
namespace Cryville.Common.Unity.UI {
|
||||||
[RequireComponent(typeof(TextMeshProUGUI))]
|
[RequireComponent(typeof(TextMeshProUGUI))]
|
||||||
@@ -29,12 +30,14 @@ namespace Cryville.Common.Unity.UI {
|
|||||||
else if (DefaultShader) ifont.material.shader = DefaultShader;
|
else if (DefaultShader) ifont.material.shader = DefaultShader;
|
||||||
if (_font == null) {
|
if (_font == null) {
|
||||||
_font = ifont;
|
_font = ifont;
|
||||||
|
Logger.Log("main", 1, "UI", "Using main font: {0}", typeface.FullName);
|
||||||
if (MaxFallbackCount <= 0) break;
|
if (MaxFallbackCount <= 0) break;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (_font.fallbackFontAssetTable == null)
|
if (_font.fallbackFontAssetTable == null)
|
||||||
_font.fallbackFontAssetTable = new List<FontAsset>();
|
_font.fallbackFontAssetTable = new List<FontAsset>();
|
||||||
_font.fallbackFontAssetTable.Add(ifont);
|
_font.fallbackFontAssetTable.Add(ifont);
|
||||||
|
Logger.Log("main", 1, "UI", "Using fallback font #{0}: {1}", _font.fallbackFontAssetTable.Count, typeface.FullName);
|
||||||
if (_font.fallbackFontAssetTable.Count >= MaxFallbackCount) break;
|
if (_font.fallbackFontAssetTable.Count >= MaxFallbackCount) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
26
Assets/Cryville/Common/Unity/UrlOpener.cs
Normal file
26
Assets/Cryville/Common/Unity/UrlOpener.cs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
namespace Cryville.Common.Unity {
|
||||||
|
public static class UrlOpener {
|
||||||
|
public static void Open(string url) {
|
||||||
|
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
|
||||||
|
System.Diagnostics.Process.Start(url);
|
||||||
|
#elif UNITY_ANDROID
|
||||||
|
using (var clazz = new UnityEngine.AndroidJavaClass("world.cryville.common.unity.UrlOpener")) {
|
||||||
|
clazz.CallStatic("open", url);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#error Unknown platform.
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
public static void OpenThreaded(string url) {
|
||||||
|
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
|
||||||
|
Open(url);
|
||||||
|
#elif UNITY_ANDROID
|
||||||
|
UnityEngine.AndroidJNI.AttachCurrentThread();
|
||||||
|
Open(url);
|
||||||
|
UnityEngine.AndroidJNI.DetachCurrentThread();
|
||||||
|
#else
|
||||||
|
#error Unknown platform.
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Cryville/Common/Unity/UrlOpener.cs.meta
Normal file
11
Assets/Cryville/Common/Unity/UrlOpener.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c827ee181de8c51499777e5a822981b8
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
17
Assets/Cryville/Common/Unity/UrlOpener.java
Normal file
17
Assets/Cryville/Common/Unity/UrlOpener.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package world.cryville.common.unity;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
|
import com.unity3d.player.UnityPlayer;
|
||||||
|
import com.unity3d.player.UnityPlayerActivity;
|
||||||
|
|
||||||
|
public final class UrlOpener {
|
||||||
|
private UrlOpener() { }
|
||||||
|
|
||||||
|
static UnityPlayerActivity activity;
|
||||||
|
|
||||||
|
public static void open(String url) {
|
||||||
|
if (activity == null) activity = (UnityPlayerActivity)UnityPlayer.currentActivity;
|
||||||
|
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
|
||||||
|
}
|
||||||
|
}
|
||||||
32
Assets/Cryville/Common/Unity/UrlOpener.java.meta
Normal file
32
Assets/Cryville/Common/Unity/UrlOpener.java.meta
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e2d08ba79acb0564b9802b57dbc2f8d3
|
||||||
|
PluginImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
iconMap: {}
|
||||||
|
executionOrder: {}
|
||||||
|
defineConstraints: []
|
||||||
|
isPreloaded: 0
|
||||||
|
isOverridable: 0
|
||||||
|
isExplicitlyReferenced: 0
|
||||||
|
validateReferences: 1
|
||||||
|
platformData:
|
||||||
|
- first:
|
||||||
|
Android: Android
|
||||||
|
second:
|
||||||
|
enabled: 1
|
||||||
|
settings: {}
|
||||||
|
- first:
|
||||||
|
Any:
|
||||||
|
second:
|
||||||
|
enabled: 0
|
||||||
|
settings: {}
|
||||||
|
- first:
|
||||||
|
Editor: Editor
|
||||||
|
second:
|
||||||
|
enabled: 0
|
||||||
|
settings:
|
||||||
|
DefaultValueInitialized: true
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using Cryville.Common.Collections.Specialized;
|
using Cryville.Common.Collections.Specialized;
|
||||||
|
using Cryville.Crtr.Skin;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Cryville.Crtr {
|
namespace Cryville.Crtr {
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: cfa7de3f6f944914d9999fcfda245f97
|
|
||||||
timeCreated: 1637552994
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: b38d66b3e6e5d94438c72f855c4efff9
|
|
||||||
timeCreated: 1637554149
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
10
Assets/Cryville/Crtr/Browsing/ChartDetail.cs
Normal file
10
Assets/Cryville/Crtr/Browsing/ChartDetail.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using Cryville.Common;
|
||||||
|
using Cryville.Crtr.Extension;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Cryville.Crtr.Browsing {
|
||||||
|
public struct ChartDetail {
|
||||||
|
public AsyncDelivery<Texture2D> Cover { get; set; }
|
||||||
|
public ChartMeta Meta { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Cryville/Crtr/Browsing/ChartDetail.cs.meta
Normal file
11
Assets/Cryville/Crtr/Browsing/ChartDetail.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5f9870328bccefa4d8d4f6d5e3cef591
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 477e04b1ed5b60e48886fb76081245c5
|
|
||||||
timeCreated: 1637722157
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -3,6 +3,7 @@ using Cryville.Common.Unity;
|
|||||||
using Cryville.Crtr.Extension;
|
using Cryville.Crtr.Extension;
|
||||||
using Cryville.Crtr.Extensions;
|
using Cryville.Crtr.Extensions;
|
||||||
using Cryville.Crtr.Extensions.Umg;
|
using Cryville.Crtr.Extensions.Umg;
|
||||||
|
using Cryville.Crtr.UI;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -66,7 +67,7 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
var coverFile = item.GetFiles(meta.cover);
|
var coverFile = item.GetFiles(meta.cover);
|
||||||
if (coverFile.Length > 0) {
|
if (coverFile.Length > 0) {
|
||||||
cover = new AsyncDelivery<Texture2D>();
|
cover = new AsyncDelivery<Texture2D>();
|
||||||
var task = new LoadTextureTask(Game.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
|
var task = new LoadTextureTask(PlatformConfig.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
|
||||||
cover.CancelSource = task.Cancel;
|
cover.CancelSource = task.Cancel;
|
||||||
Game.NetworkTaskWorker.SubmitNetworkTask(task);
|
Game.NetworkTaskWorker.SubmitNetworkTask(task);
|
||||||
}
|
}
|
||||||
@@ -93,7 +94,7 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
var coverFile = item.GetFiles(meta.cover);
|
var coverFile = item.GetFiles(meta.cover);
|
||||||
if (coverFile.Length > 0) {
|
if (coverFile.Length > 0) {
|
||||||
cover = new AsyncDelivery<Texture2D>();
|
cover = new AsyncDelivery<Texture2D>();
|
||||||
var task = new LoadTextureTask(Game.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
|
var task = new LoadTextureTask(PlatformConfig.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
|
||||||
cover.CancelSource = task.Cancel;
|
cover.CancelSource = task.Cancel;
|
||||||
Game.NetworkTaskWorker.SubmitNetworkTask(task);
|
Game.NetworkTaskWorker.SubmitNetworkTask(task);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 5d443a346e9a19d4eabbb0fa9ec7016f
|
|
||||||
timeCreated: 1637566071
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 3a13b7ea14b96e54ea8a7e6ba1275281
|
|
||||||
timeCreated: 1638435211
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
using Cryville.Common.ComponentModel;
|
|
||||||
using System.Reflection;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.UI;
|
|
||||||
using RangeAttribute = Cryville.Common.ComponentModel.RangeAttribute;
|
|
||||||
|
|
||||||
namespace Cryville.Crtr.Browsing {
|
|
||||||
public class PropertyPanel : MonoBehaviour {
|
|
||||||
[SerializeField]
|
|
||||||
GameObject m_bool;
|
|
||||||
[SerializeField]
|
|
||||||
GameObject m_number;
|
|
||||||
[SerializeField]
|
|
||||||
GameObject m_string;
|
|
||||||
|
|
||||||
PropertyInfo _property;
|
|
||||||
object _target;
|
|
||||||
|
|
||||||
Text _key;
|
|
||||||
Transform _valueContainer;
|
|
||||||
PropertyValuePanel _value;
|
|
||||||
|
|
||||||
#pragma warning disable IDE0051
|
|
||||||
void Awake() {
|
|
||||||
_key = transform.Find("Key").GetComponent<Text>();
|
|
||||||
_valueContainer = transform.Find("Value");
|
|
||||||
}
|
|
||||||
#pragma warning restore IDE0051
|
|
||||||
public void Load(PropertyInfo prop, object target) {
|
|
||||||
_target = target;
|
|
||||||
_property = prop;
|
|
||||||
_key.text = prop.Name;
|
|
||||||
|
|
||||||
GameObject vp;
|
|
||||||
if (prop.PropertyType == typeof(bool)) vp = m_bool;
|
|
||||||
else if (prop.PropertyType == typeof(float) || prop.PropertyType == typeof(int)) vp = m_number;
|
|
||||||
else if (prop.PropertyType == typeof(string)) vp = m_string;
|
|
||||||
else return;
|
|
||||||
_value = GameObject.Instantiate(vp, _valueContainer, false).GetComponent<PropertyValuePanel>();
|
|
||||||
if (_value is PVPNumber) {
|
|
||||||
var t = (PVPNumber)_value;
|
|
||||||
t.IntegerMode = prop.PropertyType == typeof(int);
|
|
||||||
var attr = prop.GetCustomAttributes(typeof(RangeAttribute), true);
|
|
||||||
if (attr.Length > 0) {
|
|
||||||
var u = (RangeAttribute)attr[0];
|
|
||||||
t.Range = new Vector2(u.Min, u.Max);
|
|
||||||
}
|
|
||||||
attr = prop.GetCustomAttributes(typeof(PrecisionAttribute), true);
|
|
||||||
if (attr.Length > 0) {
|
|
||||||
var u = (PrecisionAttribute)attr[0];
|
|
||||||
t.Precision = u.Precision;
|
|
||||||
}
|
|
||||||
attr = prop.GetCustomAttributes(typeof(StepAttribute), true);
|
|
||||||
if (attr.Length > 0) {
|
|
||||||
var u = (StepAttribute)attr[0];
|
|
||||||
t.MaxStep = u.Step;
|
|
||||||
}
|
|
||||||
attr = prop.GetCustomAttributes(typeof(LogarithmicScaleAttribute), true);
|
|
||||||
if (attr.Length > 0) {
|
|
||||||
t.LogarithmicMode = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_value.Callback = SetValueToObject;
|
|
||||||
GetValueFromObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GetValueFromObject() {
|
|
||||||
_value.Value = _property.GetValue(_target, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetValueToObject(object value) {
|
|
||||||
_property.SetValue(_target, value, null);
|
|
||||||
GetValueFromObject();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: bcca29fea992ac24698a213f0e2baedc
|
|
||||||
timeCreated: 1638435590
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
using System;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace Cryville.Crtr.Browsing {
|
|
||||||
public abstract class PropertyValuePanel : MonoBehaviour {
|
|
||||||
public Action<object> Callback { protected get; set; }
|
|
||||||
public abstract object Value { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: c6b4df13dea0e4a469d7e54e7e8fb428
|
|
||||||
timeCreated: 1637234060
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 256d7d3efda1f9b4c882eb42e608cc8e
|
|
||||||
timeCreated: 1638414803
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: a69c80e5f3e7bd04485bc3afc5826584
|
|
||||||
timeCreated: 1638415083
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -2,15 +2,6 @@ using Cryville.Common;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Browsing {
|
namespace Cryville.Crtr.Browsing {
|
||||||
internal abstract class BrowserItem : MonoBehaviour {
|
|
||||||
public int? Id { get; private set; }
|
|
||||||
protected ResourceItemMeta meta;
|
|
||||||
internal virtual void Load(int id, ResourceItemMeta item) {
|
|
||||||
Id = id;
|
|
||||||
meta = item;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct ResourceItemMeta {
|
public struct ResourceItemMeta {
|
||||||
public bool IsDirectory { get; set; }
|
public bool IsDirectory { get; set; }
|
||||||
public AsyncDelivery<Texture2D> Icon { get; set; }
|
public AsyncDelivery<Texture2D> Icon { get; set; }
|
||||||
11
Assets/Cryville/Crtr/Browsing/ResourceItemMeta.cs.meta
Normal file
11
Assets/Cryville/Crtr/Browsing/ResourceItemMeta.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f535064222dd08c4f8e52d6e9144079a
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
8
Assets/Cryville/Crtr/Browsing/UI.meta
Normal file
8
Assets/Cryville/Crtr/Browsing/UI.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ba8a8b6df16a9714f9785aba6adc0427
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
12
Assets/Cryville/Crtr/Browsing/UI/BrowserItem.cs
Normal file
12
Assets/Cryville/Crtr/Browsing/UI/BrowserItem.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Cryville.Crtr.Browsing.UI {
|
||||||
|
internal abstract class BrowserItem : MonoBehaviour {
|
||||||
|
public int? Id { get; private set; }
|
||||||
|
protected ResourceItemMeta meta;
|
||||||
|
internal virtual void Load(int id, ResourceItemMeta item) {
|
||||||
|
Id = id;
|
||||||
|
meta = item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Cryville/Crtr/Browsing/UI/BrowserItem.cs.meta
Normal file
11
Assets/Cryville/Crtr/Browsing/UI/BrowserItem.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c3cee963751f1ee4c9792c8c8983f51d
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -2,7 +2,7 @@ using TMPro;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Browsing {
|
namespace Cryville.Crtr.Browsing.UI {
|
||||||
internal class BrowserItemTile : BrowserItem {
|
internal class BrowserItemTile : BrowserItem {
|
||||||
#pragma warning disable IDE0044
|
#pragma warning disable IDE0044
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
@@ -45,7 +45,7 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
}
|
}
|
||||||
public void OnClick() {
|
public void OnClick() {
|
||||||
if (Id == null) return;
|
if (Id == null) return;
|
||||||
ResourceBrowser resourceBrowser = GetComponentInParent<ResourceBrowser>();
|
var resourceBrowser = GetComponentInParent<ResourceBrowser>();
|
||||||
if (_dir) resourceBrowser.OnDirectoryItemClicked(Id.Value);
|
if (_dir) resourceBrowser.OnDirectoryItemClicked(Id.Value);
|
||||||
else resourceBrowser.OnObjectItemClicked(Id.Value);
|
else resourceBrowser.OnObjectItemClicked(Id.Value);
|
||||||
}
|
}
|
||||||
11
Assets/Cryville/Crtr/Browsing/UI/BrowserItemTile.cs.meta
Normal file
11
Assets/Cryville/Crtr/Browsing/UI/BrowserItemTile.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 18dcb7d928c649f46bda005527fb6a17
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user