public void Init() { m_cache = FdoCache.Create("TestLangProj"); m_Scripture = m_cache.LangProject.TranslatedScriptureOA; // Make sure we don't call InstallLanguage during tests. m_cache.LanguageWritingSystemFactoryAccessor.BypassInstall = true; m_styleSheet = new FwStyleSheet(); m_styleSheet.Init(m_cache, m_Scripture.Hvo, (int)Scripture.ScriptureTags.kflidStyles); m_mapping = new ImportMappingInfo("emph{", "}", "Emphasis"); Options.ShowTheseStylesSetting = Options.ShowTheseStyles.All; m_dialog = new DummyCharacterMappingSettings(m_mapping, m_styleSheet, m_cache); m_dialog.StyleListHelper.MaxStyleLevel = int.MaxValue; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates (if necessary) and shows the CharacterMappingSettings dialog. /// This is a public virtual so that test code can override it. /// </summary> /// <param name="mapping">Provides intial values displayed in dialog.</param> /// ------------------------------------------------------------------------------------ protected virtual void DisplayInlineMappingDialog(ImportMappingInfo mapping) { if (m_inlineMappingDialog == null) { m_inlineMappingDialog = new CharacterMappingSettings(mapping, m_StyleSheet, m_cache, tabCtrlMappings.SelectedIndex == kiAnnotationMappingTab); m_inlineMappingDialog.IsDuplicateMapping += new CharacterMappingSettings.IsDuplicateMappingHandler(IsDup); } else { // If the "scripture" tab is not selected, force the dialog to only allow annotation mappings m_inlineMappingDialog.InitializeControls(mapping, tabCtrlMappings.SelectedIndex != 0); } m_inlineMappingDialog.ShowDialog(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add a default mapping for the given Standard Format marker if it does not exist yet. /// </summary> /// <param name="marker">The SF marker</param> /// <param name="endMarker">The end marker (or null)</param> /// <param name="importDomain">The import domain from which this marker originates</param> /// <param name="fAutoMapBtMarkers">Indicates whether markers beginning with "bt" should /// be treated as back-translation markers if possible.</param> /// <param name="isInUse">Indicates whether this marker is actually in use in one or more /// of the import files (for P6, this is currently always false since we're getting the /// markers from the STY file -- we come back in a second pass and set it to true if we /// find it in a file).</param> /// <returns>The newly added mapping info, or the existing one if already in the list /// </returns> /// ------------------------------------------------------------------------------------ public ImportMappingInfo AddDefaultMappingIfNeeded(string marker, string endMarker, ImportDomain importDomain, bool fAutoMapBtMarkers, bool isInUse) { // Look for the marker - if it is found, then we are done if (this[marker] != null) { return(this[marker]); } // Read the TEStyles XML file to generate a table of mappings if (s_defaultMappings.Count == 0) { ReadDefaultMappings(); } string styleName; bool excluded; MappingTargetType target; MarkerDomain markerDomain = (importDomain != ImportDomain.BackTrans) ? MarkerDomain.Default : MarkerDomain.BackTrans; if (importDomain == ImportDomain.Annotations) { // TODO (TE-5004): Map \rem (and possibly other markers?) automatically in annotations // domain. Probably need to have a separate import mapping set in TeStyles.xml that has // default mappings for the Annotations domain. styleName = null; excluded = s_defaultExclusions.ContainsKey(marker); //Make sure to check exclusions (TE-5703) target = MappingTargetType.TEStyle; } else if (!GetDefaultMapping(marker, out styleName, out excluded, out target, ref markerDomain)) { if (fAutoMapBtMarkers && importDomain == ImportDomain.Main && marker.StartsWith(@"\bt") && marker != @"\btc") { // pick out the corresponding vernacular marker. "\btblah" -> "\blah" string correspondingVernMarker = marker.Remove(1, 2); // if domain is DeprecatedScripture and the corresponding vernacular marker is defined... ImportMappingInfo correspondingVernMarkerInfo = this[correspondingVernMarker]; if (correspondingVernMarkerInfo != null && (correspondingVernMarkerInfo.Domain & MarkerDomain.DeprecatedScripture) != 0) { // clear the DeprecatedScripture bit. correspondingVernMarkerInfo.Domain ^= MarkerDomain.DeprecatedScripture; } if (correspondingVernMarkerInfo != null) { // If the corresponding vernacular marker is already defined... if (correspondingVernMarkerInfo.Domain != MarkerDomain.Note && (correspondingVernMarkerInfo.Domain & MarkerDomain.BackTrans) == 0 && (correspondingVernMarkerInfo.MappingTarget != MappingTargetType.TEStyle || correspondingVernMarkerInfo.StyleName != null)) { styleName = correspondingVernMarkerInfo.StyleName; target = correspondingVernMarkerInfo.MappingTarget; markerDomain = correspondingVernMarkerInfo.Domain; // We only want to map to the BackTrans domain when mapping to a paragraph // style because character styles automatically assume the domain of their // containing paragraphs. if (m_stylesheet == null || styleName == null || m_stylesheet.GetType(styleName) == (int)StyleType.kstParagraph) { markerDomain |= MarkerDomain.BackTrans; } } } else if (GetDefaultMapping(correspondingVernMarker, out styleName, out excluded, out target, ref markerDomain)) { // The corresponding vernacular marker has default mapping info so make this marker // a back translation of it - unless it is an annotation or BT. if (markerDomain == MarkerDomain.Note || markerDomain == MarkerDomain.BackTrans) { styleName = null; excluded = false; target = MappingTargetType.TEStyle; markerDomain = MarkerDomain.Default; } else { markerDomain |= MarkerDomain.BackTrans; } } } } // Create a mapping for the marker using the default mapping ImportMappingInfo newMapping = new ImportMappingInfo(marker, endMarker, excluded, target, markerDomain, styleName, null, null, isInUse, importDomain); Add(newMapping); return(newMapping); }
/// ------------------------------------------------------------------------------------ /// <summary> /// This method will add or modify a single mapping to the list view. /// </summary> /// <param name="lv">FwListView to add item to</param> /// <param name="mapping">mapping info object used to load FwListView item.</param> /// <returns>The newly added ListViewItem</returns> /// ------------------------------------------------------------------------------------ private ListViewItem LoadLVMappingItem(FwListView lv, ImportMappingInfo mapping) { return LoadLVMappingItem(lv, null, mapping); }
/// ------------------------------------------------------------------------------------ /// <summary> /// For the given mapping, compute a string to display in the details column of the /// mapping list. /// </summary> /// <param name="mapping">The mapping</param> /// <returns>String to display</returns> /// ------------------------------------------------------------------------------------ private string GetMappingDetailsAsString(ImportMappingInfo mapping) { string sSubItem = string.Empty; // if the style is excluded then don't display anything in the details column if (!mapping.IsExcluded) { switch (mapping.Domain) { case MarkerDomain.BackTrans: sSubItem = ScrImportComponents.kstidImportWizMappingDetailBackTrans; break; case MarkerDomain.Note: sSubItem = ScrImportComponents.kstidImportWizMappingDetailNotes; break; case MarkerDomain.Footnote: sSubItem = ScrImportComponents.kstidImportWizMappingDetailFootnotes; break; case MarkerDomain.Footnote | MarkerDomain.BackTrans: sSubItem = ScrImportComponents.kstidImportWizMappingDetailBTFootnotes; break; case MarkerDomain.Default: break; default: throw new Exception("Unexpected domain"); } // Figure out what the writing system's name is to display it in the list view. if (mapping.IcuLocale != null) { LgWritingSystem ws = new LgWritingSystem(m_cache, m_cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr(mapping.IcuLocale)); string wsName = ws.ShortName; if (wsName != null) { if (sSubItem != string.Empty) sSubItem += ", "; sSubItem += wsName; } } } return sSubItem; }
public void AddImportStyleProxyForMapping_InvalidWritingSystem() { CheckDisposed(); m_importer.HtStyleProxy.Clear(); ImportMappingInfo mapping = new ImportMappingInfo(@"\bye", MarkerDomain.Note, ScrStyleNames.MainBookTitle, "blah", null); m_importer.AddImportStyleProxyForMapping(mapping, m_importer.HtStyleProxy); ImportStyleProxy proxy = ((ImportStyleProxy)m_importer.HtStyleProxy[@"\bye"]); ITsPropsFactory chrysler = TsPropsFactoryClass.Create(); int cb = proxy.ParaProps.Length; ITsTextProps proxyParaProps = chrysler.DeserializePropsRgb(proxy.ParaProps, ref cb); string sHowDifferent; if (!TsTextPropsHelper.PropsAreEqual(StyleUtils.ParaStyleTextProps(ScrStyleNames.MainBookTitle), proxyParaProps, out sHowDifferent)) { Assert.Fail(sHowDifferent); } Assert.AreEqual(m_wsAnal, StyleUtils.WritingSystem(proxy.TsTextProps)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Copy constructor /// </summary> /// <param name="copy"></param> /// ------------------------------------------------------------------------------------ public ImportMappingInfo(ImportMappingInfo copy) { m_beginMarker = copy.m_beginMarker; m_endMarker = copy.m_endMarker; m_isExcluded = copy.m_isExcluded; m_mappingTarget = copy.m_mappingTarget; m_domain = copy.m_domain; m_styleName = copy.m_styleName; m_style = copy.m_style; m_icuLocale = copy.m_icuLocale; m_noteType = copy.m_noteType; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the style-name of the mapping, or if this is one of our special internal /// pseudo-styles, returns a UI-friendly version. /// </summary> /// <param name="mapping">The mapping.</param> /// ------------------------------------------------------------------------------------ internal static string MappingToUiStylename(ImportMappingInfo mapping) { switch (mapping.MappingTarget) { case MappingTargetType.ChapterLabel: return ScrImportComponents.kstidChapterLabelStyle; case MappingTargetType.TitleShort: return ScrImportComponents.kstidTitleShortStyle; case MappingTargetType.Figure: return ScrImportComponents.kstidFigureStyle; case MappingTargetType.FigureCaption: return ScrImportComponents.kstidFigureCaptionStyle; case MappingTargetType.FigureCopyright: return ScrImportComponents.kstidFigureCopyrightStyle; case MappingTargetType.FigureDescription: return ScrImportComponents.kstidFigureDescriptionStyle; case MappingTargetType.FigureFilename: return ScrImportComponents.kstidFigureFilenameStyle; case MappingTargetType.FigureLayoutPosition: return ScrImportComponents.kstidFigureLayoutPositionStyle; case MappingTargetType.FigureRefRange: return ScrImportComponents.kstidFigureRefRangeStyle; case MappingTargetType.FigureScale: return ScrImportComponents.kstidFigureScaleStyle; case MappingTargetType.TEStyle: return mapping.StyleName; default: Debug.Fail("Unexpected Mapping Target Type"); return null; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Constructor with ContextValues and MarkerDomain as a parameters. /// </summary> /// <param name="mapping">The Scr marker mapping.</param> /// <param name="ws">character or paragraph writing system</param> /// <param name="styleSheet">The style sheet</param> /// ------------------------------------------------------------------------------------ public ImportStyleProxy(ImportMappingInfo mapping, int ws, FwStyleSheet styleSheet) : this(mapping.StyleName, mapping.IsInline ? StyleType.kstCharacter : StyleType.kstParagraph, ws, ContextValues.General, mapping.Domain, styleSheet) { Excluded = mapping.IsExcluded; MappingTarget = mapping.MappingTarget; m_annotationType = mapping.NoteType; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initialize this dialog /// </summary> /// <param name="fParatextMapping"><c>true</c> if a Paratext mapping is being modified; /// <c>false</c> otherwise</param> /// <param name="mapping">Mapping object being modified</param> /// <param name="styleSheet">Stylesheet containing styles that will appear in the list /// </param> /// <param name="cache">The cache representing the DB connection</param> /// <param name="fBackTransDomainLocked">If <c>true</c>, won't allow the user to /// check or clear the BT checkbox. If the incoming mapping is for the back translation /// and has a domain of either Scripture or Footnote, these two domains remain /// enabled so the user can switch between them, but the Notes domain will be /// disabled. If the incoming mapping is not for the back translation, then /// this only affects the BT checkbox, not the domain options. /// </param> /// <param name="isAnnotationMapping">If <c>true</c>, forces this mapping to be in the /// Annotation domain.</param> /// <remarks>We separated this from the constructor so that we can create a mock object /// for testing purposes.</remarks> /// ------------------------------------------------------------------------------------ public virtual void Initialize(bool fParatextMapping, ImportMappingInfo mapping, FwStyleSheet styleSheet, FdoCache cache, bool isAnnotationMapping, bool fBackTransDomainLocked) { CheckDisposed(); m_fParatextMapping = fParatextMapping; m_cache = cache; m_scr = cache.LangProject.TranslatedScriptureOA; m_mapping = mapping; m_StyleSheet = styleSheet; m_isAnnotationMapping = isAnnotationMapping; m_fBackTransDomainLocked = fBackTransDomainLocked; m_styleListHelper.StyleSheet = styleSheet as FwStyleSheet; // // if there are items in the styles list and there is not one selected then // // set the first item to be the selected item. // if (lbStyles.SelectedIndex == -1 && lbStyles.Items.Count > 0) // lbStyles.SelectedIndex = 0; // Fill in the list selector combo box with the filters for the style list // Also set the maximum style level for the style list helper before the // style list gets filled in. cboList.Items.Clear(); cboList.Items.Add(TeResourceHelper.GetResourceString("kstidStyleFilterBasic")); cboList.Items.Add(TeResourceHelper.GetResourceString("kstidStyleFilterAllStyles")); cboList.Items.Add(TeResourceHelper.GetResourceString("kstidStyleFilterCustomList")); cboList.SelectedIndex = 1; // This code was not completely removed for the highly likely case that // it gets put back :) // switch (Options.ShowTheseStylesSetting) // { // case Options.ShowTheseStyles.Basic: // cboList.SelectedIndex = 0; // m_styleListHelper.MaxStyleLevel = 0; // break; // case Options.ShowTheseStyles.All: // cboList.SelectedIndex = 1; // m_styleListHelper.MaxStyleLevel = int.MaxValue; // break; // case Options.ShowTheseStyles.Custom: // cboList.SelectedIndex = 2; // m_styleListHelper.MaxStyleLevel = ToolsOptionsDialog.MaxStyleLevel; // break; // } chkBackTranslation.Checked = (mapping.Domain & MarkerDomain.BackTrans) != 0; // Check the appropriate button for the domain. This will cause the // style list to be loaded correctly for the domain. switch (mapping.Domain & ~MarkerDomain.BackTrans) { case MarkerDomain.Footnote: rbtnFootnotes.Checked = true; break; case MarkerDomain.Note: rbtnNotes.Checked = true; break; default: rbtnScripture.Checked = true; break; } // select the style name and add the handler for style changes. This needs // to be done after setting the domain since that causes the style list to // be loaded the first time. m_styleListHelper.SelectedStyleName = MappingToUiStylename(mapping); m_styleListHelper.StyleChosen += new StyleChosenHandler(StyleChosen); // if the selected mapping is excluded, then check the box if (chkExclude.Checked != mapping.IsExcluded) chkExclude.Checked = mapping.IsExcluded; else SetControlStatesBasedOnExcludeCheckBox(null, null); cboWritingSys.Items.Clear(); // Create a fake WS for the "Based on Context" item cboWritingSys.Items.Add(new NamedWritingSystem( TeResourceHelper.GetResourceString("kstidBasedOnContext"), null)); string initialWritingSystem = string.Empty; // Iterate through the available writing systems and add them to the writing systems // combo box. foreach (NamedWritingSystem nws in cache.LangProject.GetActiveNamedWritingSystems()) { cboWritingSys.Items.Add(nws); // If the mapping's ICULocale matches the current writing system's ICULocale, // save the string just added to the combo box so we can initialize the // combo box's value with it. if (mapping.IcuLocale == nws.IcuLocale) initialWritingSystem = nws.ToString(); } // Initialize the combo's value. cboWritingSys.SelectedIndex = (initialWritingSystem == string.Empty ? 0 : cboWritingSys.FindString(initialWritingSystem)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Update the mapping depending on the selectedStyleName's text. /// </summary> /// <param name="mapping">Mapping to update</param> /// <param name="selectedStyleName">the style selected in calling function</param> /// ------------------------------------------------------------------------------------ internal static void UpdateMapping(ImportMappingInfo mapping, string selectedStyleName) { if (s_PsuedoStyleNamesToTargetType.Count == 0) { // Populate it for first-time use. s_PsuedoStyleNamesToTargetType[ScrImportComponents.kstidFigureStyle] = MappingTargetType.Figure; s_PsuedoStyleNamesToTargetType[ScrImportComponents.kstidFigureCaptionStyle] = MappingTargetType.FigureCaption; s_PsuedoStyleNamesToTargetType[ScrImportComponents.kstidFigureCopyrightStyle] = MappingTargetType.FigureCopyright; s_PsuedoStyleNamesToTargetType[ScrImportComponents.kstidFigureDescriptionStyle] = MappingTargetType.FigureDescription; s_PsuedoStyleNamesToTargetType[ScrImportComponents.kstidFigureFilenameStyle] = MappingTargetType.FigureFilename; s_PsuedoStyleNamesToTargetType[ScrImportComponents.kstidFigureLayoutPositionStyle] = MappingTargetType.FigureLayoutPosition; s_PsuedoStyleNamesToTargetType[ScrImportComponents.kstidFigureRefRangeStyle] = MappingTargetType.FigureRefRange; s_PsuedoStyleNamesToTargetType[ScrImportComponents.kstidFigureScaleStyle] = MappingTargetType.FigureScale; s_PsuedoStyleNamesToTargetType[ScrImportComponents.kstidTitleShortStyle] = MappingTargetType.TitleShort; s_PsuedoStyleNamesToTargetType[ScrImportComponents.kstidChapterLabelStyle] = MappingTargetType.ChapterLabel; } MappingTargetType targetType; if (s_PsuedoStyleNamesToTargetType.TryGetValue(selectedStyleName, out targetType)) mapping.MappingTarget = targetType; else mapping.MappingTarget = MappingTargetType.TEStyle; mapping.StyleName = selectedStyleName; }
/// ----------------------------------------------------------------------------------- /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged /// resources; <c>false</c> to release only unmanaged resources. /// </param> /// ----------------------------------------------------------------------------------- protected override void Dispose( bool disposing ) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (IsDisposed) return; if( disposing ) { if(components != null) components.Dispose(); } m_styleListHelper = null; m_StyleSheet = null; m_mapping = null; m_cache = null; m_scr = null; base.Dispose( disposing ); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Exposes the <see cref="TeSfmImporter.AddImportStyleProxyForMapping"/> method /// </summary> /// <param name="mapping">The mapping for which the proxy entry is to be created</param> /// <param name="styleProxies">Dictionary to add the proxy to</param> /// ------------------------------------------------------------------------------------ public new void AddImportStyleProxyForMapping(ImportMappingInfo mapping, Dictionary<string, ImportStyleProxy> styleProxies) { CheckDisposed(); base.AddImportStyleProxyForMapping(mapping, styleProxies); }
public void AddImportStyleProxyForMapping_Inline() { CheckDisposed(); m_importer.HtStyleProxy.Clear(); ImportMappingInfo mapping = new ImportMappingInfo("|b{", "}", MarkerDomain.Default, "Really bold text", "de", null); int wsExpected = Cache.LanguageEncodings.GetWsFromIcuLocale("de"); m_importer.AddImportStyleProxyForMapping(mapping, m_importer.HtStyleProxy); ImportStyleProxy proxy = ((ImportStyleProxy)m_importer.HtStyleProxy[mapping.BeginMarker]); Assert.AreEqual(StyleType.kstCharacter, proxy.StyleType); ITsPropsFactory pillowtex = TsPropsFactoryClass.Create(); ITsTextProps proxyTextProps = proxy.TsTextProps; string sHowDifferent; if (!TsTextPropsHelper.PropsAreEqual(StyleUtils.CharStyleTextProps("Really bold text", wsExpected), proxyTextProps, out sHowDifferent)) { Assert.Fail(sHowDifferent); } Assert.AreEqual(ContextValues.General, m_styleSheet.FindStyle("Really bold text").Context); }
/// ------------------------------------------------------------------------------------- /// <summary> /// Constructor /// </summary> /// <param name="mapping">Provides intial values displayed in dialog.</param> /// <param name="styleSheet">Provides the character styles user can pick from.</param> /// <param name="cache">The DB cache</param> /// ------------------------------------------------------------------------------------- public DummyCharacterMappingSettings(ImportMappingInfo mapping, FwStyleSheet styleSheet, FdoCache cache): base(mapping, styleSheet, cache, false) { // No code needed so far. }
/// ------------------------------------------------------------------------------------ /// <summary> /// Can be called on an existing dialog to modify or create a new mapping. /// </summary> /// <param name="mapping">Provides initial values displayed in dialog.</param> /// <param name="forceAnnotation">true to only allow annotation domain mappings</param> /// ------------------------------------------------------------------------------------ public void InitializeControls(ImportMappingInfo mapping, bool forceAnnotation) { CheckDisposed(); Debug.Assert(mapping != null); // If we are modifying an existing mapping then load the information about it. txtBeginningMarker.Text = mapping.BeginMarker; txtEndingMarker.Text = mapping.EndMarker; txtBeginningMarker.Focus(); m_mapping = mapping; // Include all character styles mappingDetailsCtrl.m_styleListHelper.ShowOnlyStylesOfType = StyleType.kstCharacter; // Include footnote paragraph styles because they behave like character mappings. mappingDetailsCtrl.m_styleListHelper.UnionIncludeAndTypeFilter = true; mappingDetailsCtrl.Initialize(false, m_mapping, m_styleSheet, m_cache, forceAnnotation, false); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Convert the source line into unicode if necessary /// </summary> /// ------------------------------------------------------------------------------------ private string ConvertSource(string source, ImportMappingInfo markerMapping) { // If the file is already Unicode then no need to convert it. if (m_currentFile.FileEncoding != Encoding.ASCII) { return(source); } IEncConverter dataEncoding; if (markerMapping == null) { // If the marker is not mapped, use the containing paragraph's encoding. dataEncoding = m_prevDataEncoding; } else { // book markers are a special case - do not convert them if (markerMapping.BeginMarker == ScrImportSet.s_markerBook) { return(source); } if (markerMapping.IcuLocale != null) { dataEncoding = GetEncodingConverterForLocale(markerMapping.IcuLocale, markerMapping.BeginMarker); } else { // For paragraph styles or markers that do not map to existing styles, // or verse or chapter numbers or any default para char style that is // not inline get the encoder from the current domain. Otherwise use // the containing paragraph's encoder if (markerMapping.Style == null || markerMapping.IsParagraphStyle || markerMapping.StyleName == ScrStyleNames.VerseNumber || markerMapping.StyleName == ScrStyleNames.ChapterNumber || (!markerMapping.IsInline && markerMapping.StyleName == FdoResources.DefaultParaCharsStyleName)) { dataEncoding = GetEncodingConverterForMarkerDomain(markerMapping); } else { dataEncoding = m_prevDataEncoding; } } // If the marker maps to a paragraph style or pertains to a non-default domain, // then save the encoder as the current paragraph encoder if (m_domain == ImportDomain.Main && ((markerMapping.StyleName != FdoResources.DefaultParaCharsStyleName && (markerMapping.Style == null || markerMapping.IsParagraphStyle)) || (markerMapping.Domain & ~MarkerDomain.Footnote) != MarkerDomain.Default)) { m_prevDataEncoding = dataEncoding; } } // If an encoder was not found, then just return the text if (dataEncoding == null) { return(source); } // get a converter and convert the text dataEncoding.CodePageInput = kMagicCodePage; if (source != string.Empty) { try { source = dataEncoding.Convert(source); } catch (Exception e) { throw new EncodingConverterException( string.Format(ScriptureUtilsException.GetResourceString( "kstidEncConverterError"), e.Message, dataEncoding.Name), "/Beginning_Tasks/Import_Standard_Format/Unable_to_Import/Encoding_conversion_failed.htm"); } } return(source); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Constructor for runtime. /// </summary> /// <param name="mapping">Provides intial values displayed in dialog.</param> /// <param name="styleSheet">Provides the character styles user can pick from.</param> /// <param name="cache">The DB cache</param> /// <param name="fIsAnnotation">if set to <c>true</c> the current tab is for /// annotations.</param> /// ------------------------------------------------------------------------------------ public CharacterMappingSettings(ImportMappingInfo mapping, FwStyleSheet styleSheet, FdoCache cache, bool fIsAnnotation) : this() { m_resources = new ResourceManager( "SIL.FieldWorks.ScrImportComponents.ScrImportComponents", Assembly.GetExecutingAssembly()); m_cache = cache; m_styleSheet = styleSheet; InitializeControls(mapping, fIsAnnotation); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Load the mappings for a paratext project into the specified list. /// </summary> /// <param name="project">Paratext project ID</param> /// <param name="mappingList">ScrMappingList to which new mappings will be added</param> /// <param name="domain">The import domain for which this project is the source</param> /// <returns><c>true</c> if the Paratext mappings were loaded successfully; <c>false</c> /// otherwise</returns> /// ------------------------------------------------------------------------------------ public static bool LoadParatextMappings(string project, ScrMappingList mappingList, ImportDomain domain) { // If the new project ID is null, then do not load mappings. if (project == null) { return(false); } // Load the tags from the paratext project and create mappings for them. SCRIPTUREOBJECTSLib.ISCScriptureText3 scParatextText = null; try { scParatextText = new SCRIPTUREOBJECTSLib.SCScriptureTextClass(); scParatextText.Load(project); } catch (Exception ex) { Logger.WriteEvent(string.Format( "Got {0} exception loading paratext mappings (ScrImportP6Project.LoadParatextMappings):\n{1}", ex.GetType(), ex.Message)); return(false); } // TE-5802 try { for (int i = 0; true; i++) { SCRIPTUREOBJECTSLib.ISCTag tag = scParatextText.NthTag(i); if (tag == null) { break; } string marker = @"\" + tag.Marker; string endMarker = string.Empty; if (tag.Endmarker != string.Empty && tag.Endmarker != null) { endMarker = @"\" + tag.Endmarker; } // When the nth marker has an end marker, the nth + 1 marker will be // that end marker. Therefore, we have to skip those "end style" markers. if (tag.StyleType == SCRIPTUREOBJECTSLib.SCStyleType.scEndStyle) { continue; } // Create a new mapping for this marker. mappingList.AddDefaultMappingIfNeeded(marker, endMarker, domain, false, false); } SCRIPTUREOBJECTSLib.SCReference startRefPT = new SCRIPTUREOBJECTSLib.SCReference(); SCRIPTUREOBJECTSLib.SCReference endRefPT = new SCRIPTUREOBJECTSLib.SCReference(); startRefPT.Parse("GEN 1:0"); endRefPT.Parse("REV 22:21"); SCRIPTUREOBJECTSLib.ISCTextEnum scParatextTextEnum = scParatextText.TextEnum( (SCRIPTUREOBJECTSLib.SCReference)startRefPT, (SCRIPTUREOBJECTSLib.SCReference)endRefPT, (SCRIPTUREOBJECTSLib.SCTextType) 0, //scTitle | scSection | scVerseText | scNoteText | scOther) (SCRIPTUREOBJECTSLib.SCTextProperties) 0); SCRIPTUREOBJECTSLib.SCTextSegment scParatextTextSegment = new SCRIPTUREOBJECTSLib.SCTextSegmentClass(); mappingList.ResetInUseFlags(domain); while (scParatextTextEnum.Next(scParatextTextSegment) != 0) { string sMarker = @"\" + scParatextTextSegment.Tag.Marker; ImportMappingInfo mapping = mappingList[sMarker]; if (mapping != null) { mapping.SetIsInUse(domain, true); } // ENHANCE (TE-4408): Consider Detecting markers that occur in the data but are missing // from the STY file. How can we write a test for this? //else if (ScrImportFileInfo.IsValidMarker(sMarker)) //{ // mappingList.AddDefaultMappingIfNeeded(sMarker,domain, false, true); //} //else //{ // throw new ScriptureUtilsException(SUE_ErrorCode.InvalidCharacterInMarker, null, 0, // sMarker + sText, new ScrReference(scParatextTextSegment.FirstReference.BBCCCVVV)); //} } } catch (Exception ex) { Logger.WriteEvent(string.Format( "Got {0} exception loading paratext mappings (ScrImportP6Project.LoadParatextMappings):\n{1}", ex.GetType(), ex.Message)); return(false); } return(true); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Read the file to build mappings of the markers found /// </summary> /// ------------------------------------------------------------------------------------ protected void GetMappingsFromStream(TextReader reader) { string lineIn; int chapter = -1; int book = -1; int lineCount = 0; // book and chapter strings for reporting info in exceptions string sBookId = null; string sChapter = null; string sVerse = null; // Keep track of the first reference in the file int firstBook = -1; int firstChapter = -1; int firstVerse = -1; ReferenceRange currentRange = null; string marker; string lineText; string nextLineText = null; // used for read-ahead for \fig line when doing strict scanning while ((lineIn = reader.ReadLine()) != null) { lineCount++; while (GetNextMarkerFromData(lineIn, out marker, out lineText)) { // Make sure the marker is valid if (!IsValidMarker(marker)) { throw new ScriptureUtilsException(SUE_ErrorCode.InvalidCharacterInMarker, m_fileName, lineCount, lineIn, sBookId, sChapter, sVerse); } ImportMappingInfo markerMapping = GetOrCreateMarkerMapping(ref marker); if (marker == ScrImportSet.s_markerBook) { sBookId = lineText.TrimStart().ToUpperInvariant(); // save the book number in the list for this file book = ScrReference.BookToNumber(sBookId); if (book <= 0) { throw new ScriptureUtilsException(SUE_ErrorCode.InvalidBookID, m_fileName, lineCount, lineIn, sBookId, null, null); } sBookId = ScrReference.NumberToBookCode(book); // Make a new reference range with the book id and // start it out with chapter range of 0-0. AddRangeToList(currentRange); currentRange = new ReferenceRange(book, 0, 0); // If this is the first book, remember it if (firstBook == -1) { firstBook = book; } m_booksInFile.Add(book); chapter = -1; } else { // make sure that a book has been started before seeing any non-excluded markers // This error is a "strict" error because files can be added by a user before there // is a chance to exclude markers in the mappings. When the file is added from the settings // for import, then strict checking will be on. if (book == -1 && m_doStrictFileChecking) { // if the marker is not excluded then throw an error if (markerMapping != null && !markerMapping.IsExcluded) { throw new ScriptureUtilsException(SUE_ErrorCode.UnexcludedDataBeforeIdLine, m_fileName, lineCount, lineIn, null, null, null); } } if (marker == ScrImportSet.s_markerChapter) { // If there is no book, then throw an error since chapter numbers // are not valid without a book if (book == -1) { throw new ScriptureUtilsException(SUE_ErrorCode.ChapterWithNoBook, m_fileName, lineCount, lineIn, null, null, null); } try { sChapter = lineText; chapter = ScrReference.ChapterToInt(sChapter); // save the chapter number as the last chapter and possibly the first // chapter number in the range. if (currentRange.StartChapter == 0) { currentRange.StartChapter = chapter; } currentRange.EndChapter = chapter; } catch (ArgumentException) { throw new ScriptureUtilsException(SUE_ErrorCode.InvalidChapterNumber, m_fileName, lineCount, lineIn, sBookId, sChapter, null); } // If this is the first chapter, remember it if (firstChapter == -1) { firstChapter = chapter; } } else if (marker == ScrImportSet.s_markerVerse) { // If a verse is seen without a book, throw an exception if (book == -1) { throw new ScriptureUtilsException(SUE_ErrorCode.VerseWithNoBook, m_fileName, lineCount, lineIn, sBookId, null, lineText); } BCVRef firstRef = new BCVRef(book, chapter, 0); BCVRef lastRef = new BCVRef(book, chapter, 0); // check for an invalid verse number if (!BCVRef.VerseToScrRef(lineText, ref firstRef, ref lastRef) || firstRef.Verse == 0 || firstRef.Verse > lastRef.Verse) { throw new ScriptureUtilsException(SUE_ErrorCode.InvalidVerseNumber, m_fileName, lineCount, lineIn, sBookId, sChapter, lineText); } // If a chapter number has not been seen yet, then throw an exception sVerse = firstRef.Verse.ToString(); if (chapter == -1 && !SingleChapterBook(book)) { throw new ScriptureUtilsException(SUE_ErrorCode.MissingChapterNumber, m_fileName, lineCount, lineIn, sBookId, null, sVerse); } // If this is the first verse, remember it if (firstVerse == -1) { firstVerse = firstRef.Verse; } } else if (!markerMapping.IsExcluded && m_doStrictFileChecking && markerMapping.MappingTarget == MappingTargetType.Figure) { // First, we need to consider whether any following lines also need // to be read in, since the Figure parameters could be split across // lines. (TE-7669) Debug.Assert(nextLineText == null); int cExtraLinesRead = 0; string sTempMarker, sTempLineText; if (!GetNextMarkerFromData(lineText, out sTempMarker, out sTempLineText)) { while ((nextLineText = reader.ReadLine()) != null) { cExtraLinesRead++; if (GetNextMarkerFromData(nextLineText, out sTempMarker, out sTempLineText)) { // Normally, we want to break the line right before the first marker. int ichMarkerPos = nextLineText.IndexOf(sTempMarker); // But if it's a \fig*, break after the marker. if (sTempMarker == markerMapping.EndMarker) { ichMarkerPos += sTempMarker.Length; } lineText += " " + nextLineText.Substring(0, ichMarkerPos); nextLineText = nextLineText.Substring(ichMarkerPos); break; } else { lineText += " " + nextLineText; } } } string figureParams = lineText; int endMarkerLength = 0; // Validate the tokens for a mapping target (only in strict checking) if (!String.IsNullOrEmpty(markerMapping.EndMarker)) { endMarkerLength = markerMapping.EndMarker.Length; int ichEnd = figureParams.IndexOf(markerMapping.EndMarker); if (ichEnd >= 0) { figureParams = figureParams.Substring(0, ichEnd); } else { endMarkerLength = 0; // end marker is optional and not present } } string[] tokens = figureParams.Split(new char[] { '|' }); if (tokens.Length < 6) { throw new ScriptureUtilsException(SUE_ErrorCode.BadFigure, m_fileName, lineCount, lineIn, sBookId, sChapter, sVerse); } lineText = lineText.Substring(figureParams.Length + endMarkerLength); lineCount += cExtraLinesRead; } } // Mark this mapping as "in-use" because it was found in the scanned file markerMapping.SetIsInUse(m_domain, m_icuLocale, m_noteTypeHvo, true); if (m_scanInlineBackslashMarkers) { lineIn = lineText; } else { lineIn = nextLineText; nextLineText = null; if (lineIn == null) { break; } } if (string.IsNullOrEmpty(lineIn) && !string.IsNullOrEmpty(nextLineText)) { lineIn = nextLineText; nextLineText = null; } } } // Add the last range to the list AddRangeToList(currentRange); // If no books were found in the file then throw an exception if (book == -1) { throw new ScriptureUtilsException(SUE_ErrorCode.MissingBook, m_fileName, lineCount, null, null, null, null); } // If no chapters were found then throw an exception if (chapter == -1 && !SingleChapterBook(book)) { throw new ScriptureUtilsException(SUE_ErrorCode.NoChapterNumber, m_fileName, lineCount, null, sBookId, null, null); } // Store the first reference for the file m_startRef.Book = firstBook; m_startRef.Chapter = firstChapter == -1 ? 1 : firstChapter; m_startRef.Verse = firstVerse == -1 ? 1 : firstVerse; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initialize the members of a ScrMarkerMapping from an ImportMappingInfo object /// </summary> /// <param name="info"></param> /// ------------------------------------------------------------------------------------ public void InitFromImportMappingInfo(ImportMappingInfo info) { BeginMarker = info.BeginMarker; EndMarker = info.EndMarker; Excluded = info.IsExcluded; Target = (int)info.MappingTarget; Domain = (int)info.Domain; StyleRA = info.Style == null ? m_cache.LangProject.TranslatedScriptureOA.FindStyle(info.StyleName) : info.Style; ICULocale = info.IcuLocale; NoteTypeRA = info.NoteType; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates (if necessary) and shows the CharacterMappingSettings dialog. /// This is a public virtual so that test code can override it. /// </summary> /// <param name="mapping">Provides intial values displayed in dialog.</param> /// ------------------------------------------------------------------------------------ protected override void DisplayInlineMappingDialog(ImportMappingInfo mapping) { if (m_inlineMappingDialog == null) { m_inlineMappingDialog = new DummyCharacterMappingSettings(mapping, m_StyleSheet, m_cache); m_inlineMappingDialog.IsDuplicateMapping += new DummyCharacterMappingSettings.IsDuplicateMappingHandler(IsDup); } else { m_inlineMappingDialog.InitializeControls(mapping, false); // clear warningHappened flag here in our dummy dialog ((DummyCharacterMappingSettings)m_inlineMappingDialog).MappingInvalidWarningHappened = false; // This is pretty dumb, but we have to set it to cancel by default for testing purposes // because if the test asked for the OK button to be pressed but a validation error // occurs, we'll still pretend to close the dialog. If we return OK (as the user // requested), the subsequent code will think everything was okay. m_inlineMappingDialog.DialogResult = DialogResult.Cancel; } DummyCharacterMappingSettings mappingDlg = (DummyCharacterMappingSettings)m_inlineMappingDialog; if (m_MappingDialogDummyAccept) { mappingDlg.BeginningTextBox.Text = m_MappingDialogDummyData.BeginMarker; mappingDlg.EndingTextBox.Text = m_MappingDialogDummyData.EndMarker; mappingDlg.m_MappingDialogDummyData = m_MappingDialogDummyData; // fake the ok button being pressed. m_inlineMappingDialog.btnOk_Click(null, null); } else m_inlineMappingDialog.DialogResult = DialogResult.Cancel; }
/// ------------------------------------------------------------------------------------ /// <summary> /// This method will add or modify a single mapping in the list view. /// </summary> /// <param name="lv">FwListView to add item to</param> /// <param name="item">FwListView item to modify or null if a new one should be added. /// </param> /// <param name="mapping">ECMapping object used to load FwListView item.</param> /// <returns>The ListViewItem that was added or modified</returns> /// ------------------------------------------------------------------------------------ private ListViewItem LoadLVMappingItem(FwListView lv, ListViewItem item, ImportMappingInfo mapping) { bool newItem = false; if (item == null) { newItem = true; item = new ListViewItem(mapping.BeginMarker); } else { item.SubItems.Clear(); item.Text = mapping.BeginMarker; } if (mapping.IsInline) item.Text += "..." + mapping.EndMarker; item.Tag = mapping; string styleName = MappingStyleNameAsUIString(mapping); item.SubItems.Add(styleName); string sSubItem = GetMappingDetailsAsString(mapping); item.SubItems.Add(sSubItem); if (newItem) lv.Items.Add(item); return item; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add a default mapping for the given Standard Format marker if it does not exist yet. /// </summary> /// <param name="marker">The SF marker</param> /// <param name="endMarker">The end marker (or null)</param> /// <param name="importDomain">The import domain from which this marker originates</param> /// <param name="fAutoMapBtMarkers">Indicates whether markers beginning with "bt" should /// be treated as back-translation markers if possible.</param> /// <param name="isInUse">Indicates whether this marker is actually in use in one or more /// of the import files (for P6, this is currently always false since we're getting the /// markers from the STY file -- we come back in a second pass and set it to true if we /// find it in a file).</param> /// <returns>The newly added mapping info, or the existing one if already in the list /// </returns> /// ------------------------------------------------------------------------------------ public ImportMappingInfo AddDefaultMappingIfNeeded(string marker, string endMarker, ImportDomain importDomain, bool fAutoMapBtMarkers, bool isInUse) { // Look for the marker - if it is found, then we are done if (this[marker] != null) return this[marker]; // Read the TEStyles XML file to generate a table of mappings if (s_defaultMappings.Count == 0) ReadDefaultMappings(); string styleName; bool excluded; MappingTargetType target; MarkerDomain markerDomain = (importDomain != ImportDomain.BackTrans) ? MarkerDomain.Default : MarkerDomain.BackTrans; if (importDomain == ImportDomain.Annotations) { // TODO (TE-5004): Map \rem (and possibly other markers?) automatically in annotations // domain. Probably need to have a separate import mapping set in TeStyles.xml that has // default mappings for the Annotations domain. styleName = null; excluded = s_defaultExclusions.ContainsKey(marker); //Make sure to check exclusions (TE-5703) target = MappingTargetType.TEStyle; } else if (!GetDefaultMapping(marker, out styleName, out excluded, out target, ref markerDomain)) { if (fAutoMapBtMarkers && importDomain == ImportDomain.Main && marker.StartsWith(@"\bt") && marker != @"\btc") { // pick out the corresponding vernacular marker. "\btblah" -> "\blah" string correspondingVernMarker = marker.Remove(1, 2); // if domain is DeprecatedScripture and the corresponding vernacular marker is defined... ImportMappingInfo correspondingVernMarkerInfo = this[correspondingVernMarker]; if (correspondingVernMarkerInfo != null && (correspondingVernMarkerInfo.Domain & MarkerDomain.DeprecatedScripture) != 0) { // clear the DeprecatedScripture bit. correspondingVernMarkerInfo.Domain ^= MarkerDomain.DeprecatedScripture; } if (correspondingVernMarkerInfo != null) { // If the corresponding vernacular marker is already defined... if (correspondingVernMarkerInfo.Domain != MarkerDomain.Note && (correspondingVernMarkerInfo.Domain & MarkerDomain.BackTrans) == 0 && (correspondingVernMarkerInfo.MappingTarget != MappingTargetType.TEStyle || correspondingVernMarkerInfo.StyleName != null)) { styleName = correspondingVernMarkerInfo.StyleName; target = correspondingVernMarkerInfo.MappingTarget; markerDomain = correspondingVernMarkerInfo.Domain; // We only want to map to the BackTrans domain when mapping to a paragraph // style because character styles automatically assume the domain of their // containing paragraphs. if (m_stylesheet == null || styleName == null || m_stylesheet.GetType(styleName) == (int)StyleType.kstParagraph) { markerDomain |= MarkerDomain.BackTrans; } } } else if (GetDefaultMapping(correspondingVernMarker, out styleName, out excluded, out target, ref markerDomain)) { // The corresponding vernacular marker has default mapping info so make this marker // a back translation of it - unless it is an annotation or BT. if (markerDomain == MarkerDomain.Note || markerDomain == MarkerDomain.BackTrans) { styleName = null; excluded = false; target = MappingTargetType.TEStyle; markerDomain = MarkerDomain.Default; } else markerDomain |= MarkerDomain.BackTrans; } } } // Create a mapping for the marker using the default mapping ImportMappingInfo newMapping = new ImportMappingInfo(marker, endMarker, excluded, target, markerDomain, styleName, null, null, isInUse, importDomain); Add(newMapping); return newMapping; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Display the Add Character Mapping Settings dialog box /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// ------------------------------------------------------------------------------------ protected void btnAdd_Click(object sender, System.EventArgs e) { Debug.Assert(m_projectType != ProjectTypes.Paratext); // This creates (if necessary) and then displays the Character Mapping Settings // Dialog box. m_sMarkerBeingModified = null; ImportMappingInfo mapping = new ImportMappingInfo(string.Empty, string.Empty, null); DisplayInlineMappingDialog(mapping); if (m_inlineMappingDialog.DialogResult == DialogResult.OK) { // create a new mapping in the in-memory list of the settings m_settings.SetMapping(tabCtrlMappings.SelectedIndex == 0 ? MappingSet.Main : MappingSet.Notes, mapping); // put mapping into the listview ListViewItem newListViewItem = LoadLVMappingItem(m_lvCurrentMappingList, mapping); //unselect everything while (m_lvCurrentMappingList.SelectedItems.Count > 0) m_lvCurrentMappingList.SelectedItems[0].Selected = false; //select the item just added newListViewItem.Selected = true; newListViewItem.Focused = true; } m_lvCurrentMappingList.Focus(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Delete an ImportMappingInfo object from the list /// </summary> /// <param name="mapping">mapping object to delete</param> /// ------------------------------------------------------------------------------------ public void Delete(ImportMappingInfo mapping) { if (m_list.ContainsKey(mapping.BeginMarker)) { m_list.Remove(mapping.BeginMarker); m_fMappingDeleted = true; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// <param name="mapping"></param> /// <returns></returns> /// ------------------------------------------------------------------------------------ private static string MappingStyleNameAsUIString(ImportMappingInfo mapping) { // If the mapping is excluded, display an indicator instead of the style name if (mapping.IsExcluded) return ScrImportComponents.kstidExcludedData; return MappingDetailsCtrl.MappingToUiStylename(mapping); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add a mapping to the mapping list. /// </summary> /// <param name="mapping">mapping info to add to the list</param> /// ------------------------------------------------------------------------------------ public void Add(ImportMappingInfo mapping) { if (mapping == null) throw new ArgumentNullException(); if (mapping.BeginMarker == null || mapping.BeginMarker == string.Empty) throw new ArgumentException("Begin marker must be set before adding mapping to the list."); if (mapping.BeginMarker == ScrImportSet.s_markerChapter) { // REVIEW: Do we also need to do this for the Annotations domain. What does the importer expect? mapping.StyleName = ScrStyleNames.ChapterNumber; } else if (mapping.BeginMarker == ScrImportSet.s_markerVerse) { // REVIEW: Do we also need to do this for the Annotations domain. What does the importer expect? mapping.StyleName = ScrStyleNames.VerseNumber; } else if (mapping.BeginMarker == ScrImportSet.s_markerBook) { // \id markers do not have a style or domain mapping.Domain = MarkerDomain.Default; mapping.StyleName = null; } else { switch (m_mappingSet) { case MappingSet.Main: // If this is a BT marker but it's already in the list in the Default domain, clear the // BT flag and make sure it isn't being redefined. if ((mapping.Domain & MarkerDomain.BackTrans) != 0 && m_list.ContainsKey(mapping.BeginMarker)) { ImportMappingInfo existingMapping = this[mapping.BeginMarker]; if ((existingMapping.Domain & MarkerDomain.BackTrans) == 0) mapping.Domain = existingMapping.Domain; } break; case MappingSet.Notes: // If the mapping is for the annotations domain and it is marked as Note, then // set it to Default. if (mapping.Domain == MarkerDomain.Note) mapping.Domain = MarkerDomain.Default; if (mapping.Domain != MarkerDomain.Default) throw new ArgumentException("Invalid mapping domain"); break; } } m_list[mapping.BeginMarker] = mapping; mapping.HasChanged = true; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add a mapping to the mapping list. /// </summary> /// <param name="mapping">mapping info to add to the list</param> /// ------------------------------------------------------------------------------------ public void Add(ImportMappingInfo mapping) { if (mapping == null) { throw new ArgumentNullException(); } if (mapping.BeginMarker == null || mapping.BeginMarker == string.Empty) { throw new ArgumentException("Begin marker must be set before adding mapping to the list."); } if (mapping.BeginMarker == ScrImportSet.s_markerChapter) { // REVIEW: Do we also need to do this for the Annotations domain. What does the importer expect? mapping.StyleName = ScrStyleNames.ChapterNumber; } else if (mapping.BeginMarker == ScrImportSet.s_markerVerse) { // REVIEW: Do we also need to do this for the Annotations domain. What does the importer expect? mapping.StyleName = ScrStyleNames.VerseNumber; } else if (mapping.BeginMarker == ScrImportSet.s_markerBook) { // \id markers do not have a style or domain mapping.Domain = MarkerDomain.Default; mapping.StyleName = null; } else { switch (m_mappingSet) { case MappingSet.Main: // If this is a BT marker but it's already in the list in the Default domain, clear the // BT flag and make sure it isn't being redefined. if ((mapping.Domain & MarkerDomain.BackTrans) != 0 && m_list.ContainsKey(mapping.BeginMarker)) { ImportMappingInfo existingMapping = this[mapping.BeginMarker]; if ((existingMapping.Domain & MarkerDomain.BackTrans) == 0) { mapping.Domain = existingMapping.Domain; } } break; case MappingSet.Notes: // If the mapping is for the annotations domain and it is marked as Note, then // set it to Default. if (mapping.Domain == MarkerDomain.Note) { mapping.Domain = MarkerDomain.Default; } if (mapping.Domain != MarkerDomain.Default) { throw new ArgumentException("Invalid mapping domain"); } break; } } m_list[mapping.BeginMarker] = mapping; mapping.HasChanged = true; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Get the encoding converter for the current domain /// </summary> /// <returns></returns> /// ------------------------------------------------------------------------------------ private IEncConverter GetEncodingConverterForMarkerDomain(ImportMappingInfo markerMapping) { Debug.Assert(markerMapping.IcuLocale == null); string icuLocale; switch (markerMapping.Domain & ~MarkerDomain.Footnote) { case MarkerDomain.Default: icuLocale = m_currentFile.IcuLocale; if (icuLocale == null) // Get the converter from default vern WS { icuLocale = (m_domain == ImportDomain.Main) ? Cache.LangProject.DefaultVernacularWritingSystemICULocale : Cache.LangProject.DefaultAnalysisWritingSystemICULocale; } break; case MarkerDomain.BackTrans: case MarkerDomain.Note: // Get the converter from default analysis WS icuLocale = (m_domain == ImportDomain.Main) ? Cache.LangProject.DefaultAnalysisWritingSystemICULocale : m_currentFile.IcuLocale; break; default: throw new ArgumentException( "Parameter markerMapping passed to GetEncodingConverterForMarkerDomain had invalid domain"); } return GetEncodingConverterForLocale(icuLocale, markerMapping.BeginMarker); }
public void CleanUp() { // For runtime sake, do FdoCache.RestoreTestLangProj in TestFixtureTearDown unless // our individual tests really need a clean database. // FdoCache.RestoreTestLangProj(); m_dialog.Dispose(); m_dialog = null; m_mapping = null; m_styleSheet = null; m_Scripture = null; m_cache.Dispose(); m_cache = null; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Convert the source line into unicode if necessary /// </summary> /// ------------------------------------------------------------------------------------ private string ConvertSource(string source, ImportMappingInfo markerMapping) { // If the file is already Unicode then no need to convert it. if (m_currentFile.FileEncoding != Encoding.ASCII) return source; IEncConverter dataEncoding; if (markerMapping == null) { // If the marker is not mapped, use the containing paragraph's encoding. dataEncoding = m_prevDataEncoding; } else { // book markers are a special case - do not convert them if (markerMapping.BeginMarker == ScrImportSet.s_markerBook) return source; if (markerMapping.IcuLocale != null) dataEncoding = GetEncodingConverterForLocale(markerMapping.IcuLocale, markerMapping.BeginMarker); else { // For paragraph styles or markers that do not map to existing styles, // or verse or chapter numbers or any default para char style that is // not inline get the encoder from the current domain. Otherwise use // the containing paragraph's encoder if (markerMapping.Style == null || markerMapping.IsParagraphStyle || markerMapping.StyleName == ScrStyleNames.VerseNumber || markerMapping.StyleName == ScrStyleNames.ChapterNumber || (!markerMapping.IsInline && markerMapping.StyleName == FdoResources.DefaultParaCharsStyleName)) { dataEncoding = GetEncodingConverterForMarkerDomain(markerMapping); } else dataEncoding = m_prevDataEncoding; } // If the marker maps to a paragraph style or pertains to a non-default domain, // then save the encoder as the current paragraph encoder if (m_domain == ImportDomain.Main && ((markerMapping.StyleName != FdoResources.DefaultParaCharsStyleName && (markerMapping.Style == null || markerMapping.IsParagraphStyle)) || (markerMapping.Domain & ~MarkerDomain.Footnote) != MarkerDomain.Default)) { m_prevDataEncoding = dataEncoding; } } // If an encoder was not found, then just return the text if (dataEncoding == null) return source; // get a converter and convert the text dataEncoding.CodePageInput = kMagicCodePage; if (source != string.Empty) { try { source = dataEncoding.Convert(source); } catch (Exception e) { throw new EncodingConverterException( string.Format(ScriptureUtilsException.GetResourceString( "kstidEncConverterError"), e.Message, dataEncoding.Name), "/Beginning_Tasks/Import_Standard_Format/Unable_to_Import/Encoding_conversion_failed.htm"); } } return source; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Process a segment of text. If there are inline markers, then break out the /// pieces and return the next segment /// </summary> /// <param name="source">source text to process</param> /// <param name="marker">text of the marker</param> /// <param name="literalVerse">literal verse string to use</param> /// <returns>the next text segment</returns> /// ------------------------------------------------------------------------------------ private ISCTextSegment ProcessNextSegmentOfText(string source, string marker, string literalVerse) { int startPos; string startMarker = FindNextMarker(source, 0, out startPos); ImportMappingInfo markerMapping = ((ScrImportSet)m_settings).MappingForMarker(marker, m_mappingSet); // If there are no markers, return the entire string as the segment if (startMarker == null) { m_remainingLineText = string.Empty; } else if (startPos != 0 || marker != string.Empty) { // If the first marker is not at the start or if this is the very first time // through for this line, then save the text from the marker and // process the leading text (which may actually be an empty string if this // is a line beginning with a paragraph marker followed immediately by an // in-line marker). m_remainingLineText = source.Substring(startPos); source = source.Substring(0, startPos); } else { // An inline marker was found at the beginning of the line so process it now int endPos; string endMarker = FindNextMarker(source, startPos + startMarker.Length, out endPos); if (endMarker != null) { m_remainingLineText = source.Substring(endPos); int ichStartOfSegment = startPos + startMarker.Length; if (m_settings.ImportTypeEnum == TypeOfImport.Paratext5 && endPos > ichStartOfSegment) { // P5 in-line begin markers don't include the trailing space (for display // purposes), but it is required. Start markers do not end in "*", end // markers do. if (!startMarker.EndsWith("*")) { Debug.Assert(source[ichStartOfSegment] == ' ' || source[ichStartOfSegment] == '\t'); ichStartOfSegment += 1; } } source = source.Substring(ichStartOfSegment, endPos - ichStartOfSegment); } else { source = source.Substring(startPos + startMarker.Length); if (startMarker == ScrImportSet.s_markerVerse) { // Found an inline verse number (probably Paratext data). BCVRef.VerseToScrRef(source.TrimStart(), out literalVerse, out source, ref m_currentStartRef, ref m_currentEndRef); } m_remainingLineText = string.Empty; } // For inline markers, get the mapping info markerMapping = ((ScrImportSet)m_settings).MappingForMarker(startMarker, m_mappingSet); marker = startMarker; } // Build a segment to return return(new SCTextSegment(ConvertSource(source, markerMapping), marker, literalVerse, m_currentStartRef, m_currentEndRef, m_currentFile.FileName, m_lineNumber)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initialize this dialog /// </summary> /// <param name="fParatextMapping"><c>true</c> if a Paratext mapping is being modified; /// <c>false</c> otherwise</param> /// <param name="mapping">Mapping object being modified</param> /// <param name="styleSheet">Stylesheet containing styles that will appear in the list /// </param> /// <param name="cache">The cache representing the DB connection</param> /// <param name="fBackTransDomainLocked">If <c>true</c>, won't allow the user to /// check or clear the BT checkbox. If the incoming mapping is for the back translation /// and has a domain of either Scripture or Footnote, these two domains remain /// enabled so the user can switch between them, but the Notes domain will be /// disabled. If the incoming mapping is not for the back translation, then /// this only affects the BT checkbox, not the domain options. /// </param> /// <param name="isAnnotationMapping">If <c>true</c>, forces this mapping to be in the /// Annotation domain.</param> /// <remarks>We separated this from the constructor so that we can create a mock object /// for testing purposes.</remarks> /// ------------------------------------------------------------------------------------ public virtual void Initialize(bool fParatextMapping, ImportMappingInfo mapping, FwStyleSheet styleSheet, FdoCache cache, bool isAnnotationMapping, bool fBackTransDomainLocked) { CheckDisposed(); this.markerLabel.Text = mapping.BeginMarker; this.endMarkerLabel.Text = mapping.EndMarker; this.mappingDetailsCtrl.Initialize(fParatextMapping, mapping, styleSheet, cache, isAnnotationMapping, fBackTransDomainLocked); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add an Import style proxy for the given mapping and include it in the hash map. /// </summary> /// <param name="mapping">The mapping for which the proxy entry is to be created</param> /// <param name="styleProxies">Dictionary to add the proxy to</param> /// <remarks>A second styleProxy is added if the mapping has an end marker. /// </remarks> /// ------------------------------------------------------------------------------------ protected void AddImportStyleProxyForMapping(ImportMappingInfo mapping, Dictionary<string, ImportStyleProxy> styleProxies) { string styleName = mapping.StyleName; // If there is no style name and the target type is a style then don't // add a proxy entry for it. if (styleName == null && !mapping.IsExcluded && mapping.MappingTarget == MappingTargetType.TEStyle) { return; } ImportStyleProxy proxy; int ws = 0; // add the new style proxy to the hash table if (mapping.IcuLocale != null) ws = m_cache.LanguageEncodings.GetWsFromIcuLocale(mapping.IcuLocale); if (ws == 0) { // If domain is unspecified or if this is a BT marker, defer resolving the WS // until later, so it can be based on the context. if (mapping.Domain == MarkerDomain.Note) ws = m_wsAnal; else ws = -1; } if (styleName == FdoResources.DefaultParaCharsStyleName && !mapping.IsExcluded) { // Any marker that maps to "Default Paragraph Characters" should be // treated like an end marker. proxy = new ImportStyleProxy(null, 0, ws, ContextValues.EndMarker, mapping.Domain, m_styleSheet); styleProxies[mapping.BeginMarker] = proxy; // Use same proxy for end marker, if it is defined. This will cause optional \ft* // marker to be processed correctly. if (!string.IsNullOrEmpty(mapping.EndMarker)) { proxy.EndMarker = mapping.EndMarker; styleProxies[mapping.EndMarker] = proxy; } return; } else { // note that kstParagraph is overridden by real type for existing styles. proxy = new ImportStyleProxy(mapping, ws, m_styleSheet); } // make another proxy just for the end marker if (mapping.EndMarker != null && mapping.EndMarker.Length > 0) { proxy.EndMarker = mapping.EndMarker; int wsStuffAfterMarker = -1; MarkerDomain endMarkerDomain = MarkerDomain.Default; if (proxy.StyleType != StyleType.kstParagraph) endMarkerDomain = proxy.Domain; else if ((proxy.Domain & MarkerDomain.Footnote) == MarkerDomain.Footnote) endMarkerDomain = proxy.Domain ^ MarkerDomain.Footnote; styleProxies[mapping.EndMarker + "\uFEFF" + mapping.BeginMarker] = new ImportStyleProxy( null, //for an EndMarker, most params are irrelevant 0, wsStuffAfterMarker, ContextValues.EndMarker, endMarkerDomain, m_styleSheet); } styleProxies[mapping.BeginMarker] = proxy; }
public void AddImportStyleProxyForMapping_Normal() { CheckDisposed(); m_importer.HtStyleProxy.Clear(); ImportMappingInfo mapping = new ImportMappingInfo(@"\hello", MarkerDomain.Default, ScrStyleNames.MainBookTitle, "de", null); int wsExpected = Cache.LanguageEncodings.GetWsFromIcuLocale("de"); m_importer.AddImportStyleProxyForMapping(mapping, m_importer.HtStyleProxy); ImportStyleProxy proxy = ((ImportStyleProxy)m_importer.HtStyleProxy[@"\hello"]); Assert.AreEqual(StyleType.kstParagraph, proxy.StyleType); ITsPropsFactory pillowtex = TsPropsFactoryClass.Create(); int cb = proxy.ParaProps.Length; ITsTextProps proxyParaProps = pillowtex.DeserializePropsRgb(proxy.ParaProps, ref cb); string sHowDifferent; if (!TsTextPropsHelper.PropsAreEqual(StyleUtils.ParaStyleTextProps(ScrStyleNames.MainBookTitle), proxyParaProps, out sHowDifferent)) { Assert.Fail(sHowDifferent); } Assert.AreEqual(wsExpected, StyleUtils.WritingSystem(proxy.TsTextProps)); }