public static LongFont ParseFont(string ShortHandFont) { LongFont result = new LongFont(); var tokenizer = new FontTokenizer(ShortHandFont); string token = tokenizer.ConsumeNextTrim(); var trylist = TryList; int count = trylist.Count(); for (int i = 0; i < count; i++) { var item = trylist[i]; string value = item.Method(token); if (!string.IsNullOrEmpty(value)) { AssignValue(result, item.State, value); token = tokenizer.ConsumeNextTrim(); continue; } else { for (int j = i + 1; j < count; j++) { var nextitem = trylist[j]; string nextvalue = nextitem.Method(token); if (!string.IsNullOrEmpty(nextvalue)) { AssignValue(result, nextitem.State, nextvalue); token = tokenizer.ConsumeNextTrim(); i = i - 1; goto nextloop; } } break; } nextloop: { continue; } } while (!string.IsNullOrEmpty(token)) { result.FontFamilyList.Add(token.Trim()); token = tokenizer.ConsumeNextTrim(); } return(result); }
private static void AssignValue(LongFont font, TryState state, string value) { switch (state) { case TryState.Stretch: if (font.FontStretch == "normal") { font.FontStretch = value; } break; case TryState.Style: if (font.FontStyle == "normal") { font.FontStyle = value; } break; case TryState.Variant: if (font.FontVariant == "normal") { font.FontVariant = value; } break; case TryState.Weight: { if (font.FontWeight == "normal") { font.FontWeight = value; } } break; case TryState.FontSize: { if (font.FontSize == "medium") { font.FontSize = value; } } break; default: break; } }