/// <summary> /// Helper method that adds the current noun to a list. Follows the following rules: /// 1. If gender length is 0: doesn't add, since not a useful word /// 2. If the word length is 0: take the same word as last time. Reasoning behind this: words with double gender are present as WORD {m} {f} /// 3. All values get trimmed /// </summary> /// <param name="word"></param> /// <param name="gender"></param> /// <param name="list"></param> private void AddNoun(StringBuilder word, StringBuilder gender, List <Lemma> list) { if (gender.Length > 0) { Noun item = new Noun(); item.Gender = NounGenderConvert.ToGender(ToTrimmedString(gender)); item.Word = ToTrimmedString(word); if (item.Word.Length == 0) { // take same word as last time if (list.Count > 0) { item.Word = list.Last().Word; } else { return; } } list.Add(item); } sbType.Clear(); sbWord.Clear(); }
private void lbxResults_DrawItem(object sender, DrawItemEventArgs e) { Noun lemma = (Noun)lbxResults.Items[e.Index]; e.DrawBackground(); Graphics g = e.Graphics; Color bgColor; switch (lemma.Gender) { case Noun.NounGender.Mannlich: bgColor = Color.SkyBlue; break; case Noun.NounGender.Weiblich: bgColor = Color.Pink; break; case Noun.NounGender.Neutrum: bgColor = Color.Gold; break; default: bgColor = Color.LightGoldenrodYellow; break; } g.FillRectangle(new SolidBrush(bgColor), e.Bounds); float scaleFactor = FindFontScaleHor(g, string.Format("{0} ({1})", lemma.Word, NounGenderConvert.ToString(lemma.Gender)), defaultHeaderFont, e.Bounds.Width); Font lemmaHeaderFont = new Font(headerFontFamily, 25 * scaleFactor, FontStyle.Bold, GraphicsUnit.Pixel); Font lemmaGenderFont = new Font(headerFontFamily, 15 * scaleFactor, FontStyle.Italic, GraphicsUnit.Pixel); int headerHeight = GetFontLineHeight(lemmaHeaderFont); Rectangle lemmaRect = new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, headerHeight); lemmaRect.Width = Convert.ToInt32(Math.Ceiling(g.MeasureString(lemma.Word, lemmaHeaderFont).Width)); g.DrawString(lemma.Word, lemmaHeaderFont, Brushes.LightSlateGray, lemmaRect); int genderOffset = GetFontAscent(lemmaHeaderFont) - GetFontAscent(lemmaGenderFont); int genderHeight = GetFontLineHeight(lemmaGenderFont); Rectangle genderRect = new Rectangle(lemmaRect.Width, e.Bounds.Y + genderOffset, e.Bounds.Width - lemmaRect.Width, genderHeight); g.DrawString(string.Format("({0})", NounGenderConvert.ToString(lemma.Gender)), lemmaGenderFont, Brushes.LightSlateGray, genderRect); e.DrawFocusRectangle(); }
private void lbxResults_MeasureItem(object sender, MeasureItemEventArgs e) { Noun lemma = (Noun)lbxResults.Items[e.Index]; float scaleFactor = FindFontScaleHor(e.Graphics, string.Format("{0} ({1})", lemma.Word, NounGenderConvert.ToString(lemma.Gender)), defaultHeaderFont, lbxResults.Width); Font lemmaHeaderFont = new Font(headerFontFamily, 25 * scaleFactor, FontStyle.Bold, GraphicsUnit.Pixel); Font lemmaGenderFont = new Font(headerFontFamily, 15 * scaleFactor, FontStyle.Italic, GraphicsUnit.Pixel); e.ItemHeight = Convert.ToInt32(GetFontLineHeight(lemmaHeaderFont) * 1.15); }