/// ------------------------------------------------------------------------------------ /// <summary> /// Find (or create and store) the ImportStyleProxy for the given style and context. /// </summary> /// <param name="sStyle">name of a paragraph style</param> /// <param name="context">ignored in XML import</param> /// <param name="defaultWs">The default writing system to use when creating a new style /// proxy.</param> /// <returns>The style proxy</returns> /// ------------------------------------------------------------------------------------ public static ImportStyleProxy GetXmlParaStyleProxy(string sStyle, ContextValues context, int defaultWs) { ImportStyleProxy proxy; if (string.IsNullOrEmpty(sStyle)) sStyle = ScrStyleNames.NormalParagraph; if (!s_styleProxies.TryGetValue(sStyle, out proxy)) { proxy = new ImportStyleProxy(sStyle, StyleType.kstParagraph, defaultWs, context, s_styleSheet); s_styleProxies.Add(sStyle, proxy); } return proxy; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Find (or create and store) the ImportStyleProxy for the given style and context. /// </summary> /// <param name="sStyle">name of a paragraph style</param> /// <param name="context">ignored in XML import</param> /// <param name="defaultWs">The default writing system to use when creating a new style /// proxy.</param> /// <returns>The style proxy</returns> /// ------------------------------------------------------------------------------------ public static ImportStyleProxy GetXmlParaStyleProxy(string sStyle, ContextValues context, int defaultWs) { ImportStyleProxy proxy; if (string.IsNullOrEmpty(sStyle)) { sStyle = ScrStyleNames.NormalParagraph; } if (!s_styleProxies.TryGetValue(sStyle, out proxy)) { proxy = new ImportStyleProxy(sStyle, StyleType.kstParagraph, defaultWs, context, s_styleSheet); s_styleProxies.Add(sStyle, proxy); } return(proxy); }
/// <summary> /// Executes in two distinct scenarios. /// /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing"></param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// /// If subclasses override this method, they should call the base implementation. /// </remarks> protected virtual void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (m_isDisposed) return; if (disposing) { // Dispose managed resources here. if (m_ParaBldr != null) m_ParaBldr.Dispose(); } // Dispose unmanaged resources here, whether disposing is true or false. m_ParaBldr = null; m_cache = null; m_styleSheet = null; m_scr = null; m_undoManager = null; m_importCallbacks = null; m_ScrSectionHeadParaProxy = null; m_DefaultIntroSectionHeadParaProxy = null; m_DefaultScrParaProxy = null; m_DefaultIntroParaProxy = null; m_BTStrBldrs = null; m_SavedParaBldr = null; m_CurrFootnote = null; m_ttpChapterNumber = null; m_sPrevBook = null; m_scrBook = null; m_currSection = null; m_isDisposed = true; }
/// <summary> /// Executes in two distinct scenarios. /// /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing"></param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// /// If subclasses override this method, they should call the base implementation. /// </remarks> protected override void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (m_isDisposed) return; if (disposing) { // Dispose managed resources here. } // Dispose unmanaged resources here, whether disposing is true or false. if (m_cpe != null && Marshal.IsComObject(m_cpe)) Marshal.ReleaseComObject(m_cpe); m_cpe = null; m_settings = null; m_SOWrapper = null; m_sSegmentText = null; m_sMarker = null; m_styleProxy = null; m_vernParaStyleProxy = null; m_vernTextProps = null; m_analTextProps = null; m_styleProxies = null; m_notesStyleProxies = null; m_lastPara = null; m_BookTitleParaProxy = null; m_DefaultFootnoteParaProxy = null; m_TsStringFactory = null; m_BTFootnoteStrBldr = null; m_CurrParaPictures = null; m_CurrParaFootnotes = null; m_BTPendingPictures = null; m_CurrBTFootnote = null; m_sBtFootnoteParaStyle = null; m_BtFootnoteStrBldrs = null; m_PendingAnnotations = null; m_BTfootnoteIndex = null; m_sCharStyleEndMarker = null; m_sFootnoteEndMarker = null; m_sCharStyleBeginMarker = null; m_sFootnoteBeginMarker = null; m_scrTranslatorAnnotationDef = null; base.Dispose(disposing); }
/// ------------------------------------------------------------------------------------ /// <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; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Resets importer state variables for the new book /// Need to reset a few more things than the base class. /// </summary> /// ------------------------------------------------------------------------------------ protected override void ResetStateVariablesForNewBook() { base.ResetStateVariablesForNewBook(); m_nChapter = 1; m_foundAChapter = false; m_iNextBtPara = 0; m_vernParaStyleProxy = null; m_lastPara = null; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Prepares a new Scripture section section (if needed). Used when the imported data /// switches from book title or background information to scripture data. /// </summary> /// ------------------------------------------------------------------------------------ private void PrepareForFirstScriptureSection() { FinalizePrevParagraph(); // If there isn't a current section or there is and the section has content, then // create an implicit section break before chapter one, verse one of the scripture. // Otherwise an implicit section won't be created since it's assumed the current // section is the beginning of scripture data (as opposed to intro. or background // material. if (m_settings.ImportTranslation && m_importDomain == ImportDomain.Main && (m_currSection == null || !m_currSection.IsValidObject() || m_currSection.ContentOA.ParagraphsOS.Count > 0)) { MakeSection(); } m_fInScriptureText = true; m_fCurrentSectionIsIntro = false; // The paragraph style is set to a default here, but may get reset later, in // ProcessSegment. We set the default here because it won't get reset later // if the current segment is marked with a character style. m_ParaBldr.ParaStylePropsProxy = m_vernParaStyleProxy = m_DefaultScrParaProxy; m_context = ContextValues.Text; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Remember info about this paragraph so we can try to find a corresponding paragraph /// later. /// </summary> /// ------------------------------------------------------------------------------------ protected void ProcessBtParaStart() { if (m_vernParaStyleProxy == null || m_vernParaStyleProxy.Context != m_styleProxy.Context) { m_iNextBtPara = 0; m_iCurrSection = 0; } else if (m_vernParaStyleProxy.Structure != m_styleProxy.Structure) { m_iNextBtPara = 0; if (m_styleProxy.Structure == StructureValues.Heading) { // If structure is going from content to heading, this is a new section, // so increment the index of the section where we should look for the matching // vern para. m_iCurrSection++; } } m_vernParaStyleProxy = (m_styleProxy.StyleType == StyleType.kstParagraph) ? m_styleProxy : m_BookTitleParaProxy; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Process a back translation segment (duh) /// </summary> /// ------------------------------------------------------------------------------------ protected void ProcessBackTransSegment() { if (m_styleProxy.Function == FunctionValues.Chapter) { ProcessStartOfChapter(); return; } if (!m_settings.ImportBackTranslation) { if (m_styleProxy.Function == FunctionValues.Verse) m_currentRef.Verse = SOWrapper.SegmentFirstRef.Verse; return; } if (CurrentBook == null) { // An interleaved BT paragraph is being imported for a book that // doesn't exist. throw new ScriptureUtilsException(SUE_ErrorCode.BackTransMissingVernBook, null, null, ScrReference.NumberToBookCode(m_nBookNumber), null, null, true); } // Any non-end marker ends a character style if (m_context != ContextValues.EndMarker) EndCharStyle(); ITsTextProps ttpBtSeg; bool fThisSegmentEndsAFootnote = false; if (m_importDomain == ImportDomain.Main) { int wsBT = BackTransWS; ttpBtSeg = GetBTProps(wsBT); if (wsBT != m_wsCurrBtPara && (m_styleProxy.Domain != MarkerDomain.Default || m_styleProxy.StyleType == StyleType.kstParagraph)) { // We're about to change which WS is being processed, so end any open character // style and/or footnote. EndCharStyle(); if (m_fInFootnote) { EndFootnote(); fThisSegmentEndsAFootnote = (m_currDomain & MarkerDomain.Footnote) == 0; } m_wsCurrBtPara = wsBT; } else if (m_context == ContextValues.EndMarker) fThisSegmentEndsAFootnote = ProcessBTEndMarker(); else if (m_fInFootnote && (m_currDomain & MarkerDomain.Footnote) != 0 && m_styleProxy.StyleType == StyleType.kstParagraph) { EndFootnote(); fThisSegmentEndsAFootnote = (m_currDomain & MarkerDomain.Footnote) == 0; } } else { ttpBtSeg = GetBTProps(m_wsCurrBtPara); if (m_context == ContextValues.EndMarker) fThisSegmentEndsAFootnote = ProcessBTEndMarker(); } if (m_importDomain == ImportDomain.BackTrans && ProcessingParagraphStart) { if (m_fInFootnote) { EndFootnote(); fThisSegmentEndsAFootnote = (m_currDomain & MarkerDomain.Footnote) == 0; } AddBackTranslations(); } if (!m_fInScriptureText && m_styleProxy.Context == ContextValues.Text && m_styleProxy.Structure == StructureValues.Body) { // If this BT segment is a scripture body segment and we don't already have // a paragraph started, this file must have an implicit paragraph start, // so we initialize the member that holds the para style proxy for the // corresponding vernacular para so we'll have something reasonable to // look for when we go to find the corresponding para. if (m_BTStrBldrs.Count == 0 && m_importDomain == ImportDomain.BackTrans) m_vernParaStyleProxy = m_DefaultScrParaProxy; m_fInScriptureText = true; m_iNextBtPara = 0; } ITsStrBldr strbldr; if (m_BTStrBldrs.ContainsKey(m_wsCurrBtPara)) { // We continue to use the existing BT para builder (for this WS) until the // vernacular paragraph -- and hence any BT paragraph(s) -- get written. // This means that if the BT contains spurious paragraph markers, their // segments will just be appended to the one-and-only BT paragraph (for this // WS) already being built. // TODO: Generate an error annotation. Debug.Assert(m_wsCurrBtPara != 0); strbldr = m_BTStrBldrs[m_wsCurrBtPara]; } else { if (ProcessingParagraphStart) { if (m_importDomain == ImportDomain.Main) { if (m_vernParaStyleProxy == null || m_vernParaStyleProxy.StyleId == null) { // Got an unexpected BT paragraph segment. A BT paragraph came before // any vernacular paragraph in the import stream. int verse = SOWrapper.SegmentFirstRef.Verse; throw new ScriptureUtilsException(SUE_ErrorCode.BackTransMissingVernPara, SOWrapper.CurrentFileName, SOWrapper.CurrentLineNumber, m_sMarker + " " + m_sSegmentText, m_fFoundABook ? CurrentBook.BookId : null, m_foundAChapter ? m_nChapter.ToString() : null, (verse > 0) ? verse.ToString() : null, true); } if (m_vernParaStyleProxy.StyleId != m_styleProxy.StyleId && m_styleProxy.Style.Type != StyleType.kstCharacter) { // Got an unexpected BT paragraph segment. The paragraph style of the BT // paragraph doesn't match the style of the corresponding (i.e., // preceding) vernacular paragraph. int verse = SOWrapper.SegmentFirstRef.Verse; throw new ScriptureUtilsException(SUE_ErrorCode.BackTransStyleMismatch, m_sMarker + " " + m_sSegmentText, string.Format( TeResourceHelper.GetResourceString("kstidBTStyleMismatchDetails"), m_styleProxy.StyleId, m_vernParaStyleProxy.StyleId), m_fFoundABook ? CurrentBook.BookId : null, m_foundAChapter ? m_nChapter.ToString() : null, (verse > 0) ? verse.ToString() : null, true); } } // Non-interleaved BT else { ProcessBtParaStart(); } } strbldr = TsStrBldrClass.Create(); Debug.Assert(m_wsCurrBtPara != 0); m_BTStrBldrs[m_wsCurrBtPara] = strbldr; } if (m_context == ContextValues.Title) { SetBookName(); if (m_fInBookTitle) { // We have another segment to add to the current title AddBookTitleSegment(strbldr, m_vernParaStyleProxy, ttpBtSeg); return; } m_fInBookTitle = true; } AddPendingVerseAndChapterNumsToBackTrans(GetVerseRefAsString(m_wsCurrBtPara), m_wsCurrBtPara, strbldr); if ((m_currDomain & MarkerDomain.Footnote) != 0 && !fThisSegmentEndsAFootnote) { if (m_BTFootnoteStrBldr == null) { if (m_fInFootnote) { // This BT footnote ends the vernacular footnote being built EndFootnote(); } // remember that we are now processing a footnote SetInFootnote(); CheckDataForFootnoteMarker(); m_BTFootnoteStrBldr = TsStrBldrClass.Create(); m_sBtFootnoteParaStyle = (m_styleProxy.StyleType == StyleType.kstCharacter) ? m_DefaultFootnoteParaProxy.StyleId : m_styleProxy.StyleId; if (m_importDomain == ImportDomain.Main) { // If we aren't importing the vernacular... (TE-7445) if (!m_settings.ImportTranslation) { // attempt to find an existing vernacular paragraph that corresponds // to the back translation para. bool append; m_lastPara = FindCorrespondingVernParaForSegment(m_vernParaStyleProxy.Style, m_currentRef, out append); m_CurrParaFootnotes = (m_lastPara != null ? (m_lastPara as StTxtPara).GetFootnotes() : null); } m_CurrBTFootnote = FindCorrespondingFootnote(m_sBtFootnoteParaStyle); if (m_CurrBTFootnote == null) { int verse = SOWrapper.SegmentFirstRef.Verse; throw new ScriptureUtilsException(SUE_ErrorCode.BackTransMissingVernFootnote, SOWrapper.CurrentFileName, SOWrapper.CurrentLineNumber, m_sMarker + " " + m_sSegmentText, m_fFoundABook ? CurrentBook.BookId : null, m_foundAChapter ? m_nChapter.ToString(): null, (verse > 0) ? verse.ToString() : null, true); } } else { m_CurrBTFootnote = null; } } strbldr = m_BTFootnoteStrBldr; if (m_styleProxy.StyleType == StyleType.kstCharacter && m_styleProxy.Context != ContextValues.EndMarker) { SetInCharacterStyle(); } } else if (m_styleProxy.StyleType == StyleType.kstCharacter && m_styleProxy.Function != FunctionValues.Verse) { SetInCharacterStyle(); } // Add a line break between section head segments if we're processing // interleaved back translation section heading segments. if (m_fInSectionHeading && strbldr.Length > 0 && ProcessingParagraphStart && m_importDomain == ImportDomain.Main) { AddTextToPara(kHardLineBreak, ttpBtSeg, strbldr); } AddTextToPara(m_sSegmentText, ttpBtSeg, strbldr); }
/// ------------------------------------------------------------------------------------ /// <summary> /// See if current segment is a verse number, and if so process the verse number part /// of it. Also prepare to handle any text following the number (vernacular stream /// only). /// </summary> /// <returns>true if the segment was processed as a verse number</returns> /// ------------------------------------------------------------------------------------ private bool HandleVerseNumbers() { if (m_styleProxy.Function != FunctionValues.Verse) return false; ProcessVerseNumbers(); // Prepare to insert the verse text into the paragraph as plain vernacular text. m_sSegmentText = m_sSegmentText.TrimStart(); // When we go to add the actual text, we want the character properties to // contain only the writing system, not the character properties for the verse // number style. The resulting run will inherit its character formatting from // whatever paragraph style is in effect. To achieve this, we arbitrarily pick // a vernacular paragraph style here and get its proxy. Its character properties // are guaranteed to contain only a writing system. m_styleProxy = m_DefaultScrParaProxy; return true; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add a new annotation to the pending list /// </summary> /// ------------------------------------------------------------------------------------ private void AddNewAnnotation(ImportStyleProxy paraProxy, ITsTextProps runProps) { StTxtParaBldr paraBldr = new StTxtParaBldr(m_cache); paraBldr.ParaStylePropsProxy = paraProxy; paraBldr.AppendRun(m_sSegmentText, runProps); Guid guidAnnotationType = Guid.Empty; try { if (paraProxy.NoteType != null) guidAnnotationType = paraProxy.NoteType.Guid; else if (m_SOWrapper.CurrentAnnotationType > 0) guidAnnotationType = m_cache.GetGuidFromId(m_SOWrapper.CurrentAnnotationType); } catch { } finally { if (guidAnnotationType == Guid.Empty) guidAnnotationType = m_scrTranslatorAnnotationDef.Guid; } BCVRef lastRef = SOWrapper.SegmentLastRef; // If we haven't come across any scripture text (still in title or intro), then make // sure that the chapter number is set right. if (lastRef.Chapter == 0) lastRef.Chapter = 1; m_PendingAnnotations.Add(new ScrAnnotationInfo(guidAnnotationType, paraBldr, (m_ParaBldr.Length > 0 ? m_ParaBldr.Length - 1 : 0), m_currentRef.BBCCCVVV, lastRef.BBCCCVVV)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets a style proxy for processing a segment /// </summary> /// <returns>the style proxy</returns> /// ------------------------------------------------------------------------------------ private ImportStyleProxy GetStyleProxy() { Dictionary<string, ImportStyleProxy> styleProxies = (m_importDomain == ImportDomain.Annotations ? m_notesStyleProxies : m_styleProxies); ImportStyleProxy proxy; if (styleProxies.TryGetValue(m_sMarker, out proxy)) { return proxy; } else if (m_fInCharStyle && styleProxies.TryGetValue(m_sMarker + "\uFEFF" + m_sCharStyleBeginMarker, out proxy)) { // Character style proxy return proxy; } else if (m_fInFootnote && styleProxies.TryGetValue(m_sMarker + "\uFEFF" + m_sFootnoteBeginMarker, out proxy)) { // Footnote proxy return proxy; } // Didn't find a proxy for the marker, so create a new one based off the marker // and the current import domain MarkerDomain domain = MarkerDomain.Default; switch (m_importDomain) { case ImportDomain.Main: domain = MarkerDomain.Default; break; case ImportDomain.BackTrans: domain = MarkerDomain.BackTrans; break; case ImportDomain.Annotations: domain = MarkerDomain.Note; break; } m_unmappedMarkers.Add(m_sMarker); return styleProxies[m_sMarker] = new ImportStyleProxy( m_sMarker, StyleType.kstParagraph, GetWsForImportDomain(), m_fInScriptureText ? ContextValues.Text : ContextValues.Intro, domain, m_styleSheet); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Process this scripture text segment /// </summary> /// ------------------------------------------------------------------------------------ protected void ProcessSegment() { if (m_importCallbacks.CancelImport) StopImport(); m_styleProxy = GetStyleProxy(); // Excluded markers are thrown away, but if it is an inline marker, we // need to look for the end marker. if (m_styleProxy.Excluded || (m_styleProxy.Function == FunctionValues.StanzaBreak && (m_vernParaStyleProxy == null || m_vernParaStyleProxy.Function != FunctionValues.Line))) { // REVIEW: Should we call SetInCharStyle here? if (m_styleProxy.EndMarker != null) m_fInCharStyle = true; // treat this like a character style return; } // Confirm that we have a book at this point if we are ready to start importing data or // that we are currently processing the \id line to get a book // Needed to add a specific check to allow annotations when there isn't a book since new // books are imported to saved versions and won't be found. if (m_styleProxy.Context == ContextValues.Book) { // processing /id line } else if (m_nBookNumber == 0 && m_importDomain == ImportDomain.Annotations) { throw new ScriptureUtilsException(SUE_ErrorCode.UnexcludedDataBeforeIdLine, SOWrapper.CurrentFileName, SOWrapper.CurrentLineNumber, m_sMarker + " " + m_sSegmentText, string.Empty, string.Empty, string.Empty); } else if (m_scrBook == null && m_settings.ImportTranslation && m_settings.ImportBackTranslation) { throw new ScriptureUtilsException(SUE_ErrorCode.UnexcludedDataBeforeIdLine, SOWrapper.CurrentFileName, SOWrapper.CurrentLineNumber, m_sMarker + " " + m_sSegmentText, string.Empty, string.Empty, string.Empty); } if (HandleSpecialTargets()) return; CheckForPendingFootnoteText(); #region Footnote Target Refs if (m_styleProxy.StyleId == ScrStyleNames.FootnoteTargetRef) { if (m_fInFootnote && m_CurrFootnote != null && m_fInterpretFootnoteSettings) { Debug.Assert(m_ParaBldr != null); ImportStyleProxy proxy = (ImportStyleProxy)m_ParaBldr.ParaStylePropsProxy; m_scr.SetDisplayFootnoteReference(proxy.StyleId, true); } // else... TODO: Maybe write an error out to the error log (if we had one) // if (m_styleProxy.EndMarker != null) // { // } SetInCharacterStyle(); // treat this like a character style return; } #endregion GetSegmentInfo(); // Assume we need to insert the text at the end of this method bool fInsertSegment = true; if (HandleStartOfBook() || SkipThisBook) return; // Handle the case of non-interleaved and interleaved notes. if (m_importDomain == ImportDomain.Annotations || m_currDomain == MarkerDomain.Note) { HandleNoteDomain(); return; } if (SkipIntroMaterial()) return; #region Back translation domain handling // Handle the case of non-interleaved and interleaved back translations. if (m_importDomain == ImportDomain.BackTrans || (m_currDomain & MarkerDomain.BackTrans) != 0) { ProcessBackTransSegment(); return; } else if (!m_settings.ImportTranslation) { if (!m_fInScriptureText && m_styleProxy.Context == ContextValues.Text && m_styleProxy.Structure == StructureValues.Body) { PrepareForFirstScriptureSection(); m_iNextBtPara = 0; } else { if (ProcessingParagraphStart) { FinalizePrevParagraph(); if (m_vernParaStyleProxy == null || m_vernParaStyleProxy.Structure != m_styleProxy.Structure) m_iNextBtPara = 0; } HandleSectionHead(ref fInsertSegment); } } // Remember the paragraph style for future BT processing. if (ProcessingParagraphStart) { m_vernParaStyleProxy = (m_styleProxy.StyleType == StyleType.kstParagraph) ? m_styleProxy : m_BookTitleParaProxy; m_fBackTransVerseNumPending = false; } #endregion #region End Marker if (m_context == ContextValues.EndMarker) { if (ProcessEndMarker()) return; } else { // This segment implicitly terminates any char style run EndCharStyle(); } #endregion #region Start of Chapter if (m_styleProxy.Function == FunctionValues.Chapter) { ProcessStartOfChapter(); // don't insert this segment into the body text because it's already been handled. fInsertSegment = false; } #endregion if (m_settings.ImportTranslation) { HandleBookTitle(ref fInsertSegment); HandleSectionHead(ref fInsertSegment); HandleFootnotes(ref fInsertSegment); #region Make an Implicit Scripture Section if necessary // Prepare for the switch from book title or background material to real // "Scripture" text. if (!m_fInScriptureText && m_styleProxy.Context == ContextValues.Text && m_styleProxy.Structure == StructureValues.Body) { PrepareForFirstScriptureSection(); } #endregion } bool isVerse = HandleVerseNumbers(); if (!m_settings.ImportTranslation) { if (m_styleProxy.StyleType == StyleType.kstCharacter) SetInCharacterStyle(); return; } if (!isVerse) HandleOtherParagraphStyles(); if (fInsertSegment) InsertSegment(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initialize the scripture importer /// </summary> /// ------------------------------------------------------------------------------------ protected void Initialize() { m_wsAnal = m_cache.DefaultAnalWs; m_wsVern = m_cache.DefaultVernWs; m_wsPara = m_cache.DefaultVernWs; m_scr = m_cache.LangProject.TranslatedScriptureOA; InitInterpretFootnoteSettings(); ScrImportSet importSettings = (m_settings as ScrImportSet); // ENHANCE (TomB): Might want to make it possible to end importing in the middle // of a book someday. ScrReference endRef = new ScrReference(importSettings.EndRef, m_scr.Versification); ScrReference startRef = new ScrReference(importSettings.StartRef, m_scr.Versification); m_nBookNumber = importSettings.StartRef.Book; importSettings.EndRef = endRef = endRef.LastReferenceForBook; // Initialize scripture object InitScriptureObject(); // Load the scripture text project & enum LoadScriptureProject(); // Display progress if one was supplied if (m_importCallbacks.IsDisplayingUi) { int cChapters = ScrReference.GetNumberOfChaptersInRange(SOWrapper.BooksPresent, startRef, endRef); int nMax = m_settings.ImportTranslation ? cChapters : 0; if (SOWrapper.HasNonInterleavedBT && m_settings.ImportBackTranslation) nMax += cChapters; if (SOWrapper.HasNonInterleavedNotes && m_settings.ImportAnnotations) nMax += cChapters; m_importCallbacks.Maximum = nMax; } // Init our set of style proxies LoadImportMappingProxies(); // Init member vars special paragraph style proxies, used as fallbacks in case // import data lacks a paragraph style. // For now we always use the default vernacular writing system. This may change // when we are able to import paratext project proxies with multiple // domains (vern, back transl, notes) m_BookTitleParaProxy = new ImportStyleProxy(ScrStyleNames.MainBookTitle, StyleType.kstParagraph, m_wsVern, ContextValues.Title, m_styleSheet); Debug.Assert(m_BookTitleParaProxy.Context == ContextValues.Title); m_ScrSectionHeadParaProxy = new ImportStyleProxy(ScrStyleNames.SectionHead, StyleType.kstParagraph, m_wsVern, ContextValues.Text, m_styleSheet); m_DefaultIntroSectionHeadParaProxy = new ImportStyleProxy(ScrStyleNames.IntroSectionHead, StyleType.kstParagraph, m_wsVern, ContextValues.Intro, m_styleSheet); m_DefaultScrParaProxy = new ImportStyleProxy(ScrStyleNames.NormalParagraph, StyleType.kstParagraph, m_wsVern, ContextValues.Text, m_styleSheet); m_DefaultIntroParaProxy = new ImportStyleProxy(ScrStyleNames.IntroParagraph, StyleType.kstParagraph, m_wsVern, ContextValues.Intro, m_styleSheet); m_DefaultFootnoteParaProxy = new ImportStyleProxy(ScrStyleNames.NormalFootnoteParagraph, StyleType.kstParagraph, m_wsVern, ContextValues.Note, m_styleSheet); m_DefaultAnnotationStyleProxy = new ImportStyleProxy(ScrStyleNames.Remark, StyleType.kstParagraph, m_wsAnal, ContextValues.Annotation, m_styleSheet); // Make a paragraph builder. We will keep re-using this every time we build a paragraph. m_ParaBldr = new StTxtParaBldr(m_cache); // Handle the case where the very first marker (after the \id line) is a // character style. m_ParaBldr.ParaStylePropsProxy = m_DefaultIntroParaProxy; // Build generic character props for use with different runs of text and analysis // character properties ITsPropsBldr tsPropsBldr = TsPropsBldrClass.Create(); // analysis character properties tsPropsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, m_wsAnal); m_analTextProps = tsPropsBldr.GetTextProps(); // vernacular character properties tsPropsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, m_wsVern); m_vernTextProps = tsPropsBldr.GetTextProps(); // Get a reference to the annotation definition of translator notes (to use as default note type) m_scrTranslatorAnnotationDef = new CmAnnotationDefn(m_cache, LangProject.kguidAnnTranslatorNote); }
/// ----------------------------------------------------------------------------------- /// <summary> /// Perform some basic initialization. /// </summary> /// ----------------------------------------------------------------------------------- private void Initialize() { m_wsAnal = m_cache.DefaultAnalWs; m_wsVern = m_cache.DefaultVernWs; m_scr = m_cache.LangProject.TranslatedScriptureOA; m_ScrSectionHeadParaProxy = new ImportStyleProxy(ScrStyleNames.SectionHead, StyleType.kstParagraph, m_wsVern, ContextValues.Text, m_styleSheet); m_DefaultIntroSectionHeadParaProxy = new ImportStyleProxy(ScrStyleNames.IntroSectionHead, StyleType.kstParagraph, m_wsVern, ContextValues.Intro, m_styleSheet); m_DefaultScrParaProxy = new ImportStyleProxy(ScrStyleNames.NormalParagraph, StyleType.kstParagraph, m_wsVern, ContextValues.Text, m_styleSheet); m_DefaultIntroParaProxy = new ImportStyleProxy(ScrStyleNames.IntroParagraph, StyleType.kstParagraph, m_wsVern, ContextValues.Intro, m_styleSheet); // Make a paragraph builder. We will keep re-using this every time we build a paragraph. m_ParaBldr = new StTxtParaBldr(m_cache); }