// Render a symbol inside the given rectangle. private void RenderSymbol(IRenderer renderer, Symbol symbol, float left, float top, float right, float bottom, RectangleF clipRect) { if (symbol == null) return; RectangleF rect = new RectangleF(left, top, right - left, bottom - top); if (!rect.IntersectsWith(clipRect)) return; renderer.DrawSymbol(symbol, rect); }
public void DrawSymbol(Symbol sym, RectangleF rect) { sym.Draw(g, Color.Black, rect); }
// Is this a dual-main symbol (two different main symbols in D and E) bool IsDualMainSymbol(Symbol[] symbols) { return (symbols[1] != null && symbols[2] != null && symbols[2].Kind == 'D' && symbols[2].Id != symbols[1].Id); }
public void DrawSymbol(Symbol symbol, RectangleF rect) { PointSymDef symdef; Pair<object, Symbol> key = new Pair<object, Symbol>(this, symbol); // The dictionary is used to contains symdefs for each symbol. if (dict.ContainsKey(key)) { symdef = (PointSymDef) dict[key]; } else { symdef = symbol.CreateSymdef(map, color, Geometry.TransformDistance(rect.Height, currentTransform)); dict[key] = symdef; } PointSymbol sym = new PointSymbol(symdef, Geometry.TransformPoint(new PointF(rect.X + rect.Width / 2, rect.Y + rect.Height / 2), currentTransform), 0, null); map.AddSymbol(sym); }
// Add a symbol, if non-null, to the current text. The symbol text is assumed to be a formatting string where {0} has current text string AddSymbolToCurrent(string current, string gender, Symbol symbol) { if (symbol == null) return current; else return string.Format(GetSymbolText(symbol, gender), current); }
string GetTextFromSize(string size, bool useDeepOrHigh, bool firstIsDeep, string genderFirst, bool secondIsDeep, string genderSecond, out Symbol symbolControllingNounCase) { symbolControllingNounCase = null; // If it's a combo, figure out which kind and the correct combining word. Symbol combiner = null; int index = size.IndexOf('|'); if (index >= 0) { combiner = symbolDB["9.4"]; } else { index = size.IndexOf('/'); if (index >= 0) { combiner = firstIsDeep ? symbolDB["9.3deep"] : symbolDB["9.3high"]; symbolControllingNounCase = combiner; useDeepOrHigh = false; } else { index = size.IndexOf('x'); if (index >= 0) { combiner = symbolDB["9.2"]; symbolControllingNounCase = combiner; useDeepOrHigh = false; } } } if (combiner != null) { // Combo string Symbol firstSymbolControllingNounCase; string firstText = GetTextFromSize(size.Substring(0, index), useDeepOrHigh, firstIsDeep, genderFirst, firstIsDeep, genderFirst, out firstSymbolControllingNounCase); string secondText = GetTextFromSize(size.Substring(index + 1), useDeepOrHigh, secondIsDeep, genderSecond, secondIsDeep, genderSecond); if (string.IsNullOrEmpty(firstText) || string.IsNullOrEmpty(secondText)) { return size; } else { if (symbolControllingNounCase == null) symbolControllingNounCase = firstSymbolControllingNounCase; return string.Format(combiner.GetText(language, genderFirst), firstText, secondText); } } else { // Simple string. // Trim spaces and any "m" suffix. size = size.Trim(); if (size.EndsWith("m", StringComparison.InvariantCulture)) { size = size.Substring(0, size.Length - 1); } // Convert to a double. Allow the current culture, US and french cultures (to allow either "." or "," as the decimal point.) double value; if (double.TryParse(size, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, null, out value) || double.TryParse(size, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, CultureInfo.GetCultureInfo("en-US"), out value) || double.TryParse(size, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, CultureInfo.GetCultureInfo("fr-FR"), out value)) { string text = Convert.ToString(value) + "m"; if (useDeepOrHigh) { Symbol symbol = firstIsDeep ? symbolDB["9.1deep"] : symbolDB["9.1high"]; symbolControllingNounCase = symbol; return string.Format(symbol.GetText(language, genderFirst), text); } else { return text; } } else return size; } }
Symbol[] GetSymbols(ControlPoint controlPoint) { string[] ids = controlPoint.symbolIds; Symbol[] symbols = new Symbol[ids.Length]; for (int i = 0; i < ids.Length; ++i) { if (ids[i] != null) symbols[i] = symbolDB[ids[i]]; } return symbols; }
// Select a line in the key public void SelectKeyLine(Symbol keySymbol) { SetSelection(SelectionKind.Key, Id<CourseControl>.None, Id<CourseControl>.None, Id<ControlPoint>.None, Id<Special>.None, keySymbol, DescriptionLine.TextLineKind.None); }
Symbol GetSingleVersionOfComboSymbol(Symbol comboSymbol) { return symbolDB[comboSymbol.Id + "single"]; }
// Get the modified case for a symbol. Checks the eventDB for overrides to the symbol text; otherwise uses the default for the symbol. string GetSymbolModifiedCase(Symbol symbol) { Event ev = eventDB.GetEvent(); string id = symbol.Id; if (ev.customSymbolText.ContainsKey(id) && Symbol.ContainsLanguage(ev.customSymbolText[id], language)) return Symbol.GetModifiedCase(symbolDB, ev.customSymbolText[id], language); else return symbol.GetModifiedCase(language); }
// Get the text associated with the main feature. Normally this is just the symbol in column D. But, // there could be a second main feature in column E. Also handles crossing/junction in column F and between in column G. string GetMainFeatureText(ControlPoint controlPoint, Symbol[] symbols, out string mainFeatureGender) { string mainFeature, mainFeaturePlural, mainFeatureCase, secondaryFeature = null; bool comboUsed = false; mainFeatureGender = ""; if (symbols[1] == null) return ""; // no main symbol. // Get the main feature (column D) and secondary feature (column E, if a column D symbol is there) mainFeatureCase = GetNounCase(controlPoint, false, false, false); mainFeature = GetSymbolText(symbols[1], "", mainFeatureCase); mainFeatureGender = GetSymbolGender(symbols[1]); mainFeaturePlural = GetSymbolPluralText(symbols[1], "", mainFeatureCase); if (symbols[2] != null) { if (symbols[2].Kind == 'D') { // Additional feature used for combination. secondaryFeature = GetSymbolText(symbols[2], "", mainFeatureCase); if (secondaryFeature == mainFeature) secondaryFeature = null; // we treate "road/road/crossing" the same as "road/ /crossing" ==> "road crossing". } else if (symbols[2].Kind == 'E') { // Modifier to the main feature. string modifier = GetSymbolText(symbols[2], mainFeatureGender); mainFeature = string.Format(modifier, mainFeature); if (mainFeaturePlural != null) { string pluralModifier; pluralModifier = GetSymbolPluralText(symbols[2], mainFeatureGender); mainFeaturePlural = string.Format(pluralModifier, mainFeaturePlural); } } } // Do we have crossing/junction combo? if (symbols[3] != null) { mainFeature = CombineSymbols(symbols[3], mainFeature, mainFeaturePlural, secondaryFeature, out mainFeaturePlural, out mainFeatureGender); secondaryFeature = null; comboUsed = true; } // Do have have a between combo? (Note that we can have BOTH a between and a crossing combo.) if (symbols[4] != null && symbols[4].Id == "11.15") { mainFeature = CombineSymbols(symbols[4], mainFeature, mainFeaturePlural, secondaryFeature, out mainFeaturePlural, out mainFeatureGender); comboUsed = true; } if (!comboUsed && secondaryFeature != null) { // No combo symbol present, but a secondary regular symbol present in column E. This is non-standard. mainFeature = CombineSymbols(symbolDB["basic_combo"], mainFeature, mainFeaturePlural, secondaryFeature, out mainFeaturePlural, out mainFeatureGender); } return mainFeature; }
// Create a combination string for crossing/junction/between. string CombineSymbols(Symbol comboSymbol, string mainFeature, string mainFeaturePlural, string secondaryFeature, out string pluralCombo, out string gender) { pluralCombo = null; if (secondaryFeature == null && mainFeaturePlural != null) { Symbol singleComboSymbol = GetSingleVersionOfComboSymbol(comboSymbol); pluralCombo = string.Format(singleComboSymbol.GetPluralText(language), mainFeature, mainFeaturePlural); gender = singleComboSymbol.GetGender(language); return string.Format(singleComboSymbol.GetText(language), mainFeature, mainFeaturePlural); } else { pluralCombo = string.Format(comboSymbol.GetPluralText(language), mainFeature, secondaryFeature == null ? mainFeature : secondaryFeature); gender = comboSymbol.GetGender(language); return string.Format(comboSymbol.GetText(language), mainFeature, secondaryFeature == null ? mainFeature : secondaryFeature); } }
string ApplyNounCase(Symbol symbol, string currentNounCase) { // Get the case to apply to the modified symbol. string modifiedNounCase = GetSymbolModifiedCase(symbol); // If it wasn't empty, use, otherwise use the current one. if (string.IsNullOrEmpty(modifiedNounCase)) return currentNounCase; else return modifiedNounCase; }
private void ReadSymbolFile(string filename) { using (XmlInput xmlinput = new XmlInput(filename)) { xmlinput.CheckElement("symbols"); bool first = true; while (xmlinput.FindSubElement(first, new string[] { "symbol", "language" })) { if (xmlinput.Name == "symbol") { Symbol symbol = new Symbol(this); symbol.ReadXml(xmlinput); symbols.Add(symbol.Id, symbol); } else if (xmlinput.Name == "language") { SymbolLanguage language = new SymbolLanguage(); language.ReadXml(xmlinput); languages.Add(language.LangId, language); } first = false; } } }
// Get the text for a symbol. Checks the eventDB for overrides to the symbol text; otherwise uses the default for the symbol. string GetSymbolText(Symbol symbol, string gender, string nounCase = "") { Event ev = eventDB.GetEvent(); string id = symbol.Id; if (ev.customSymbolText.ContainsKey(id) && Symbol.ContainsLanguage(ev.customSymbolText[id], language)) return Symbol.GetBestSymbolText(symbolDB, ev.customSymbolText[id], language, false, gender, nounCase); else return symbol.GetText(language, gender, nounCase); }
// The images for given symbols are cached, so we only render each one once. Image GetSymbolImage(Symbol symbol) { if (!symbolImageCache.ContainsKey(symbol.Id)) { // Create a bitmap and draw into it. Bitmap bm = new Bitmap(symbol.IsWide ? boxSize * 8 : boxSize, boxSize); Graphics g = Graphics.FromImage(bm); g.Clear(Color.Transparent); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; symbol.Draw(g, Color.Black, new RectangleF(0, 0, bm.Width, bm.Height)); g.Dispose(); symbolImageCache.Add(symbol.Id, bm); } return symbolImageCache[symbol.Id]; }
string GetTextFromColumnF(string columnFText, Symbol[] symbols, out Symbol symbolControllingNounCase) { bool firstIsDeep, secondIsDeep; string genderFirst = "", genderSecond = ""; firstIsDeep = secondIsDeep = (symbols[1] != null && symbols[1].SizeIsDepth); if (symbols[1] != null) genderFirst = GetSymbolGender(symbols[1]); if (symbols[2] != null && symbols[2].Kind == 'D') { secondIsDeep = symbols[2].SizeIsDepth; genderSecond = GetSymbolGender(symbols[2]); } return GetTextFromSize(columnFText, true, firstIsDeep, genderFirst, secondIsDeep, genderSecond, out symbolControllingNounCase); }
// Sets the current selection. No feedback is provided as to whether the selection // is valid; if invalid, the selection will simply be cleared when it is retrieved. private void SetSelection(SelectionKind selectionKind, Id<CourseControl> courseControlId, Id<CourseControl> courseControlId2, Id<ControlPoint> controlId, Id<Special> specialId, Symbol keySymbol, DescriptionLine.TextLineKind textLineKind) { if (this.selectionKind != selectionKind || this.selectedCourseControl != courseControlId || this.selectedCourseControl2 != courseControlId2 || this.selectedControl != controlId || this.selectedSpecial != specialId) { controller.ScrollHighlightIntoView = true; // scroll the newly selection item into view. } ++selectionChangeNum; this.selectionKind = selectionKind; this.selectedCourseControl = courseControlId; this.selectedCourseControl2 = courseControlId2; this.selectedControl = controlId; this.selectedSpecial = specialId; this.selectedKeySymbol = keySymbol; this.selectedTextLineKind = textLineKind; }
// Add columnH info string AddColumnHString(string current, Symbol symbol) { if (symbol == null) return current; else return string.Format("{0} ({1})", current, GetSymbolText(symbol, "")); }