/// <summary> /// Calculates pinyin layout. /// </summary> private void doAnalyzePinyin(Graphics g) { // If already measured, nothing to do if (pinyinInfo != null) { return; } // This is how we measure StringFormat sf = StringFormat.GenericTypographic; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; pinyinInfo = new PinyinInfo(); // Measure each pinyin syllable bool diacritics = true; var pcoll = entry.GetPinyinForDisplay(diacritics, res.PinyinHiliteStart, res.PinyinHiliteLength, out pinyinInfo.HiliteStart, out pinyinInfo.HiliteLength); float cx = headInfo.HeadwordRight + (float)padMid; float ctop = padTop; for (int i = 0; i != pcoll.Count; ++i) { PinyinSyllable ps = pcoll[i]; // New pinyin block PinyinBlock pb = new PinyinBlock(); // Text: syllable's display text string text = ps.GetDisplayString(true); pb.TextPos = textPool.PoolString(text); // If text is punctuation, glue it to previous syllable if (text.Length == 1 && CedictFormatter.SticksLeft(text) && i > 0) { cx -= pinyinSpaceWidth; } // Block's size and relative location SizeF sz = g.MeasureString(text, getFont(fntPinyinHead), 65535, sf); pb.Rect = new RectangleF(cx, ctop, sz.Width, sz.Height); cx += sz.Width + pinyinSpaceWidth; // Add block pinyinInfo.Blocks.Add(pb); } // Height of whole pinyin area pinyinInfo.PinyinHeight = pinyinInfo.Blocks[0].Rect.Height; }
private void renderSpecialSense(StringBuilder sb, string equiv) { sb.Append("<span class='sense-meta'>"); sb.Append(HtmlEncoder.Default.Encode(TextProvider.Instance.GetString(lang, "displayEntry.classifier"))); sb.Append(' '); sb.Append("</span>"); equiv = equiv.Substring(equiv.IndexOf(':') + 1); string[] items = equiv.Split(','); bool first = true; foreach (string itm in items) { char ch1 = '\0'; char ch2 = '\0'; string pinyin = null; for (int i = 0; i != itm.Length; ++i) { char c = itm[i]; if (i == 0) { ch1 = c; } else if (i == 1 && c == '|') { continue; } else if (i == 1 && c == '[') { pinyin = ""; continue; } else if (i == 1) { break; } else if (i == 2 && pinyin == null) { ch2 = c; continue; } else if (i == 2) { pinyin += c; continue; } else if (i == 3 && c == '[') { pinyin = ""; continue; } else if (c != ']') { pinyin += c; } } if (ch1 == '\0' || pinyin == null) { continue; } if (!first) { sb.Append("; "); } // We have simp + trad if (ch2 != '\0') { if (script == UiScript.Simp) { sb.Append(HtmlEncoder.Default.Encode(ch2.ToString())); } else if (script == UiScript.Trad) { sb.Append(HtmlEncoder.Default.Encode(ch1.ToString())); } else { sb.Append(HtmlEncoder.Default.Encode(ch2.ToString())); sb.Append("·"); sb.Append(HtmlEncoder.Default.Encode(ch1.ToString())); } } // Simp=Trad else { sb.Append(HtmlEncoder.Default.Encode(ch1.ToString())); } sb.Append("·"); PinyinSyllable psl = null; try { if (pinyin.Length < 2) { continue; } int tone; if (!int.TryParse(pinyin.Substring(pinyin.Length - 1), out tone)) { tone = 0; } psl = new PinyinSyllable(pinyin.Substring(0, pinyin.Length - 1), tone); } catch { } if (psl != null) { sb.Append(HtmlEncoder.Default.Encode(psl.GetDisplayString(true))); } else { sb.Append(HtmlEncoder.Default.Encode(pinyin)); } first = false; } }