/// <summary> /// Gets sense display string from entry, leaving traditional/simplified away for monolingual searches. /// </summary> private string getSense(int senseIx) { var cs = entry.GetSenseAt(senseIx); string res = ""; if (!cs.Domain.EqualsPlainText("CL:")) { string domain = CedictFormatter.HybridToHtml(cs.Domain, script); domain = CedictFormatter.StripPlainFromHtml(domain); res += domain; } if (cs.Equiv != HybridText.Empty) { if (res != string.Empty) { res += " "; } string equiv = CedictFormatter.HybridToHtml(cs.Equiv, script); equiv = CedictFormatter.StripPlainFromHtml(equiv); res += equiv; } if (cs.Note != HybridText.Empty) { if (res != string.Empty) { res += " "; } string note = CedictFormatter.HybridToHtml(cs.Note, script); note = CedictFormatter.StripPlainFromHtml(note); res += note; } return(res); }
/// <summary> /// Fire command for label index (in <see cref="lblColl"/>). /// </summary> private void fire(int ix) { // Prepare plain text for clipboard, and optionally (for formatted full entry), also html. string plainText = "text"; string html = null; // Our plain text options Label lbl = lblColl[ix]; if (lbl == lblHanzi1) { plainText = script == SearchScript.Traditional ? entry.ChTrad : entry.ChSimpl; } else if (lbl == lblHanzi2) { plainText = entry.ChTrad; } else if (lbl == lblPinyin) { plainText = CedictFormatter.GetPinyinString(entry.GetPinyinForDisplay(true)); } else if (lbl == lblFullCedict) { plainText = CedictFormatter.GetCedict(entry); } else if (lbl == lblFullFormatted) { html = CedictFormatter.GetHtml(tprov, entry, script); plainText = CedictFormatter.StripPlainFromHtml(html); } else if (lbl == lblSense) { html = CedictFormatter.GetSenseHtml(entry.GetSenseAt(senseIx), script); plainText = CedictFormatter.StripPlainFromHtml(html); } // Copy to clipboard: plain text if (html == null) { Clipboard.SetText(plainText); } // Copy to clipboard: formatted HTML else { ClipboardHelper.CopyToClipboard(html, plainText); } // TO-DO: // - Sense (after updating getSense to mind single search script) // !!! // - Sense ID hover behavior in OneResultControl, sense ID passed to context menu // Let parent control know that command has been triggered: time to close context menu. cmdTriggered(this); }
/// <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; }
/// <summary> /// Gets display strings by combining entry, sense index, and localized strings. /// </summary> private void getDisplayStrings(ITextProvider tprov, int senseIx, out string fullFormatted, out string fullCedict, out string hanzi1, out string hanzi2, out string pinyin, out string sense) { fullFormatted = tprov.GetString("CtxtCopyEntryFormatted"); fullCedict = tprov.GetString("CtxtCopyEntryCedict"); pinyin = tprov.GetString("CtxtCopyPinyin"); string pinyinVal = CedictFormatter.GetPinyinString(entry.GetPinyinForDisplay(true), Magic.CtxtMenuMaxSyllableLength); pinyin = string.Format(pinyin, pinyinVal); sense = null; hanzi1 = null; hanzi2 = null; if (script == SearchScript.Simplified || script == SearchScript.Traditional || entry.ChSimpl == entry.ChTrad) { hanzi1 = tprov.GetString("CtxtCopyHanzi"); string hanzi1Val = script == SearchScript.Traditional ? entry.ChTrad : entry.ChSimpl; hanzi1Val = ellipse(hanzi1Val, Magic.CtxtMenuMaxSyllableLength); hanzi1 = string.Format(hanzi1, hanzi1Val); } else { hanzi1 = tprov.GetString("CtxtCopySimplified"); string hanzi1Val = ellipse(entry.ChSimpl, Magic.CtxtMenuMaxSyllableLength); hanzi1 = string.Format(hanzi1, hanzi1Val); hanzi2 = tprov.GetString("CtxtCopyTraditional"); string hanzi2Val = ellipse(entry.ChTrad, Magic.CtxtMenuMaxSyllableLength); hanzi2 = string.Format(hanzi2, hanzi2Val); } if (senseIx != -1) { sense = tprov.GetString("CtxtCopySense"); string senseVal = getSense(senseIx); senseVal = ellipse(senseVal, Magic.CtxtMenuMaxSenseLength); sense = string.Format(sense, senseVal); } }