/// <summary> /// Method which calls at first /// </summary> async void Start() { IsLoaded = false; lstData = new List <LangData>(); textPairs = new Dictionary <string, string>(); dataSerializer = new DataContractJsonSerializer(typeof(List <LangData>)); textSerializer = new DataContractJsonSerializer( typeof(Dictionary <string, string>)); textFieldsContainer = new List <MultiLang>(); LoadLangData(); //MakeDataFile(); <-Only for debug SettingsCore sc = gameObject.GetComponent <SettingsCore>(); if (sc == null) { throw new CantFindGlobalObj("Can't find SettingsCore!"); } while (!sc.IsLoaded) { await Task.Delay(10); } CheckPropertyLang(); //MakeLangFiles(); <- Only for debug LoadLangDictionary(); IsLoaded = true; }
void Initilize() { SettingsCore sc = gameObject.GetComponent <SettingsCore>(); if (sc.ShowMessageAboutCust) { if (Settings == null) { throw new CantFindUIElement("Can't find Settings UI!"); } Settings.SetActive(true); if (FirstStartScreen == null) { throw new CantFindUIElement("Can't find first start screen on UI"); } FirstStartScreen.SetActive(true); } else { if (MainWindow == null) { throw new CantFindUIElement("Can't find Main Window UI"); } MainWindow.SetActive(true); } }
private async void CreateAsync(object window) { Window win = window as Window; string entity = ""; ConnectionCore cc = null; try { SettingsCore settings = new SettingsCore(); settings.SettingsSerialize(); cc = new Cores.ConnectionCore(new ConnectionModel(Type, ConnString)); entity = cc.CreateModel(Document.Text, settings.Settings); } catch (Exception ex) { await _dialogCoordinator.ShowMessageAsync(this, $"Error!", $"Error message: {ex.Message} /r/nStackTrace: {ex.StackTrace}"); return; } if (cc != null && cc.Errors.Count > 0) { await _dialogCoordinator.ShowMessageAsync(this, $"Error!", $"Error message: {cc.Errors.First().Message} /r/nStackTrace: {cc.Errors.First().StackTrace}"); } else { win.Tag = entity; win.DialogResult = true; win.Close(); } }
public Protection() { this.ForkProtector = new ForkProtection(Core.ProtectionType.Critical); this.SettingsManager = new SettingsCore(); this.InitializeSettings(); this.InitializeProperties(); }
protected virtual void DoChangeTheme(string sender) { var theme = ThemeManager.DetectAppStyle(Application.Current); var accent = ThemeManager.GetAccent(sender); SettingsCore settings = new SettingsCore(); settings.Settings.AccenColor = sender; settings.SettingsSerialize(); ThemeManager.ChangeAppStyle(Application.Current, accent, theme.Item1); }
/// <summary> /// Method of checking: is current language in properties containts at lstDat. /// If language not containts - loads english lang /// </summary> void CheckPropertyLang() { SettingsCore sc = gameObject.GetComponent <SettingsCore>(); foreach (LangData ld in lstData) { if (ld.langID == sc.CurrentLanguage.langID) { return; } } sc.CurrentLanguage.langID = SystemLanguage.English; }
public AppControllerCore(AppKeeper keeper, SettingsCore settings) { this._keeper = keeper ?? throw new ArgumentNullException(nameof(keeper)); this.Settings = settings ?? throw new ArgumentNullException(nameof(settings)); LanguageService.SwitchDefault(); Monitors = new ObservableCollection <MonitorViewModel>(); BindingOperations.EnableCollectionSynchronization(Monitors, _monitorsLock); NotifyIconContainer = new NotifyIconContainer(); _displayWatcher = new DisplayWatcher(); _powerWatcher = new PowerWatcher(); _brightnessWatcher = new BrightnessWatcher(); }
/// <summary> /// Method which loads dictionary of language pairs. Language which be used /// seted at Properties. /// This method can be load from another methods /// </summary> public void LoadLangDictionary() { textPairs.Clear(); string path = null; SettingsCore sc = gameObject.GetComponent <SettingsCore>(); foreach (LangData ld in lstData) { if (ld.langID == sc.CurrentLanguage.langID) { path = ld.fileName; break; } } if (path == null) { throw new NoTextFileException("Can't find pair with selected lang id!"); } TextAsset ta = Resources.Load <TextAsset>(Path.Combine("Text", path)); if (ta.bytes.Length == 0) { throw new NoTextFileException("Can't load text from " + path + ".json!"); } using (MemoryStream ms = new MemoryStream(ta.bytes, 0, ta.bytes.Length)) { textPairs = textSerializer.ReadObject(ms) as Dictionary <string, string>; } foreach (MultiLang ml in textFieldsContainer) { ml.SetText(); } }
private List <Structures.Core.TextFrame> setImageFramesFromShape(Shape shape, string imagePath, SettingsCore settings) { List <Structures.Core.TextFrame> tfs_updated = new List <Structures.Core.TextFrame>(); if ((shape.Type == PbShapeType.pbPicture //|| shape.Type == PbShapeType.pbBarCodePictureHolder || shape.Type == PbShapeType.pbLinkedPicture) && settings.ImportPictures) { Structures.Core.TextFrame tf_image = null; if (pub2xml.api.Processor.FramesDictoinary.ContainsKey(shape.ID)) { foreach (Structures.Core.TextFrame tf in pub2xml.api.Processor.FramesDictoinary[shape.ID]) { if (shape.ID == tf.shapeId && string.Compare(shape.Type.ToString(), tf.shapeType, true) == 0) { tf_image = tf; break; } } } if (tf_image != null) { if (tf_image.imageName.Trim() != string.Empty) { string imagePathFile = Path.Combine(imagePath, tf_image.imageName); if (File.Exists(imagePathFile)) { try { shape.PictureFormat.Replace(imagePathFile); //shape.PictureFormat.ReplaceEx(imagePathFile, PbPictureInsertAs.pbPictureInsertAsOriginalState, pbPictureInsertFit.pbFill); tfs_updated.Add(tf_image); } catch (Exception ex) { tf_image.message = StringResources.Picture + ": " + shape.ID + (shape.PictureFormat.Filename != string.Empty ? shape.PictureFormat.Filename : string.Empty) + "\r\n" + ex.Message; pub2xml.api.Processor.ProcessingErrors.Add(tf_image); } } } } } return(tfs_updated); }
private List <Structures.Core.TextFrame> setTextFramesFromTableFrame(Shape shape, SettingsCore settings) { List <Structures.Core.TextFrame> tfs_updated = new List <Structures.Core.TextFrame>(); #region | HasTable | if (shape.HasTable == Microsoft.Office.Core.MsoTriState.msoTrue) { foreach (Microsoft.Office.Interop.Publisher.Cell cl in shape.Table.Cells) { if (cl.HasText) { if (settings.ImportText) { List <Structures.Core.TextFrame> tf_paragraphs = new List <Structures.Core.TextFrame>(); if (pub2xml.api.Processor.FramesDictoinary.ContainsKey(shape.ID)) { foreach (Structures.Core.TextFrame tf in pub2xml.api.Processor.FramesDictoinary[shape.ID]) { if (shape.ID == tf.shapeId && cl.Column.ToString() == tf.tableColumn && cl.Row.ToString() == tf.tableRow) { tf_paragraphs.Add(tf); } } if (tf_paragraphs.Count > 0) { if (tf_paragraphs.Count == cl.TextRange.ParagraphsCount || (tf_paragraphs.Count > cl.TextRange.ParagraphsCount && cl.TextRange.ParagraphsCount == 1)) { if (tf_paragraphs.Count == cl.TextRange.ParagraphsCount) { int paragraphsCount = cl.TextRange.ParagraphsCount; List <ParagraphFormat> pfs = new List <ParagraphFormat>(); List <Font> fts = new List <Font>(); for (int i = paragraphsCount; i > 0; i--) { TextRange tr = cl.TextRange.Paragraphs(i); fts.Add(tr.Font.Duplicate()); pfs.Add(tr.ParagraphFormat.Duplicate()); } pfs.Reverse(); fts.Reverse(); for (int i = paragraphsCount; i > 0; i--) { if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.CurrentIndex, StringResources.BuildingShape + ": " + shape.ID + ", " + shape.Name + "... " + StringResources.Paragraph + ": " + i.ToString() + " (" + StringResources.TableRow + ": " + cl.Row.ToString() + ", " + StringResources.Column + ": " + cl.Column.ToString() + ")"); } TextRange tr = cl.TextRange.Paragraphs(i); Structures.Core.TextFrame tf = tf_paragraphs[(i - 1)]; string rangeText = tf.text.Replace("<r/>", "\r").Replace("<n/>", "\n"); //testing this... if (rangeText.EndsWith("\r")) { rangeText = rangeText.TrimEnd('\r'); } tr.Text = rangeText; setTaggedText(tr); tr.Font = fts[(i - 1)]; tr.ParagraphFormat = pfs[(i - 1)]; } } else { ParagraphFormat pf = cl.TextRange.ParagraphFormat.Duplicate(); Font ft = cl.TextRange.Font.Duplicate(); string rangeText = string.Empty; foreach (Structures.Core.TextFrame tf in tf_paragraphs) { rangeText += tf.text.Replace("<r/>", "\r").Replace("<n/>", "\n"); } //testing this... if (rangeText.EndsWith("\r")) { rangeText = rangeText.TrimEnd('\r'); } cl.TextRange.Text = rangeText; setTaggedText(cl.TextRange); cl.TextRange.Font = ft; cl.TextRange.ParagraphFormat = pf; } } else { throw new Exception(StringResources.TheParagraphCountsAreDifferentForShapeId + ": " + shape.ID.ToString()); } } } } } } } #endregion return(tfs_updated); }
private List <Structures.Core.TextFrame> getTextFramesFromTextFrame(Shape shape, SettingsCore settings, string pubFileName) { List <Structures.Core.TextFrame> tfs = new List <Structures.Core.TextFrame>(); #region | HasTextFrame | if (shape.HasTextFrame == Microsoft.Office.Core.MsoTriState.msoTrue) { if (shape.TextFrame.HasText == Microsoft.Office.Core.MsoTriState.msoTrue) { try { if (!shape.TextFrame.Story.TextRange.Text.Trim().StartsWith(Structures.Constants.pub2xml)) { try { if (settings.ExportText) { List <string> paragraphsText = getParagraphsText(shape.TextFrame.Story.TextRange, settings.ExportMarkupInternalFontEffects); for (int i = 0; i < paragraphsText.Count; i++) { if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.CurrentIndex, StringResources.ParsingShape + ": " + shape.ID + ", " + shape.Name + "... " + StringResources.Paragraph + ": " + (i + 1).ToString()); } Structures.Core.TextFrame tf = new Structures.Core.TextFrame(); tf.shapeId = shape.ID; tf.shapeName = shape.Name; tf.shapeType = shape.Type.ToString(); tf.tableColumn = string.Empty; tf.tableRow = string.Empty; tf.paragraph = (i + 1); tf.text = (string)paragraphsText[i].Clone(); tfs.Add(tf); } shape.TextFrame.Story.TextRange.Text = Structures.Constants.pub2xml + (settings.ExportPseudoTranslateFile ? getPseudoTranslatedText(shape.TextFrame.Story.TextRange.Text, settings.PseudoTranslateItems) : shape.TextFrame.Story.TextRange.Text); } } catch (Exception ex) { throw ex; } } } catch (Exception ex) { throw ex; } } } #endregion return(tfs); }
internal ExportPackage export(string pubFilePath, string xmlFilePath, string imagePath, SettingsCore settings) { pub2xml.api.Processor.ProcessingErrors = new List <Structures.Core.TextFrame>(); pub2xml.api.Processor.MaximumShapes = 0; pub2xml.api.Processor.CurrentIndex = 0; pub2xml.api.Processor.FramesDictoinary = null; Structures.Core.ExportPackage ep = new Structures.Core.ExportPackage(); ep.pubFilePath = pubFilePath; ep.xmlFilePath = xmlFilePath; ep.imagePath = imagePath; Application pbApp = new Application(); try { if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.MaximumShapes, StringResources.LoadingPublisherFile); } Document pbDoc = pbApp.Open(pubFilePath, false, false, PbSaveOptions.pbDoNotSaveChanges); pbDoc.ActiveWindow.Visible = false; object fileName_temp = pubFilePath + Constants.pub2xmlTempPubExtension; pbDoc.SaveAs(fileName_temp, PbFileFormat.pbFilePublication, false); #region | get total shapes count | foreach (Page page in pbDoc.MasterPages) { foreach (Shape shape in page.Shapes) { pub2xml.api.Processor.MaximumShapes++; } } foreach (Page page in pbDoc.Pages) { foreach (Shape shape in page.Shapes) { pub2xml.api.Processor.MaximumShapes++; } } #endregion pub2xml.api.Processor.CurrentIndex = 0; try { #region | MasterPages | foreach (Page page in pbDoc.MasterPages) { foreach (Shape shape in page.Shapes) { pub2xml.api.Processor.CurrentIndex++; if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.CurrentIndex, StringResources.ParsingShape + ": " + shape.ID + ", " + shape.Name + "..."); } try { List <Structures.Core.TextFrame> tfs = getTextFramesFromShape(shape, settings, ep.imagePath, Path.GetFileName(pubFilePath)); if (tfs.Count > 0) { ep.textFrames.AddRange(tfs); } } catch (Exception ex) { throw ex; } } } #endregion #region | Pages | foreach (Page page in pbDoc.Pages) { foreach (Shape shape in page.Shapes) { pub2xml.api.Processor.CurrentIndex++; if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.CurrentIndex, StringResources.ParsingShape + ": " + shape.ID + ", " + shape.Name + "..."); } try { List <Structures.Core.TextFrame> tfs = getTextFramesFromShape(shape, settings, ep.imagePath, Path.GetFileName(pubFilePath)); if (tfs.Count > 0) { ep.textFrames.AddRange(tfs); } } catch (Exception ex) { throw ex; } if (pub2xml.api.Processor.CurrentIndex % 10 == 0) { if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.CurrentIndex, StringResources.SavingChanges); } pbDoc.Save(); } } } #endregion ep.success = true; } catch (Exception ex) { ep.success = false; ep.message = ex.Message; throw ex; } finally { if (ep.success) { if (settings.ExportPseudoTranslateFile) { object fileName_vts = pubFilePath + Constants.pub2xmlPseudoTranslationExtension; pbDoc.SaveAs(fileName_vts, PbFileFormat.pbFilePublication, false); } } pbDoc.Close(); pbDoc = null; } } catch (Exception ex) { ep.success = false; ep.message = ex.Message; throw ex; } finally { if (ep.success) { if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.MaximumShapes, StringResources.SavingOutputToXmlFile); } saveExportPackage(ep); #region | create pdf | if (settings.ExportCreatePdfFile) { if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.MaximumShapes, StringResources.LoadingPublisherFile); } Document pbDoc2 = pbApp.Open(pubFilePath, false, false, PbSaveOptions.pbDoNotSaveChanges); try { if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.MaximumShapes, StringResources.SavingPDFFile); } pbDoc2.ExportAsFixedFormat(PbFixedFormatType.pbFixedFormatTypePDF, pubFilePath + Constants.pub2xmlPDFAfterExportExtension); } finally { pbDoc2.Close(); pbDoc2 = null; } } #endregion #region | remove temp file | try { if (File.Exists(pubFilePath + Constants.pub2xmlTempPubExtension)) { File.Delete(pubFilePath + Constants.pub2xmlTempPubExtension); } } catch (Exception ex) { Trace.WriteLine(ex.Message); } #endregion } pbApp = null; GC.Collect(); Process[] Processes = Process.GetProcessesByName("MSPUB"); foreach (Process p in Processes) { if (p.MainWindowTitle.Trim() == string.Empty) { p.Kill(); } } } return(ep); }
internal bool Import(string xmlFilePath, string pubFilePath, string imagePath, SettingsCore settings) { bool success = false; pub2xml.api.Processor.ProcessingErrors = new List <Structures.Core.TextFrame>(); pub2xml.api.Processor.MaximumShapes = 0; pub2xml.api.Processor.CurrentIndex = 0; pub2xml.api.Processor.FramesDictoinary = null; string fileName = pubFilePath; if (settings.ImportCreateBakFile) { string fileNameBak = pubFilePath + Constants.pub2xmlBakExtension; if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.MaximumShapes, StringResources.CreatingBackupFile); } if (File.Exists(fileNameBak)) { File.Delete(fileNameBak); } File.Copy(fileName, fileNameBak, true); } if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.MaximumShapes, StringResources.LoadingXmlFile); } Structures.Core.ExportPackage ep = ReadExportPackage(xmlFilePath); pub2xml.api.Processor.FramesDictoinary = new Dictionary <long, List <Structures.Core.TextFrame> >(); foreach (Structures.Core.TextFrame tf in ep.textFrames) { if (pub2xml.api.Processor.FramesDictoinary.ContainsKey(tf.shapeId)) { pub2xml.api.Processor.FramesDictoinary[tf.shapeId].Add(tf); } else { pub2xml.api.Processor.FramesDictoinary.Add(tf.shapeId, new List <Structures.Core.TextFrame> { tf }); } } Microsoft.Office.Interop.Publisher.Application pbApp = new Microsoft.Office.Interop.Publisher.Application(); pbApp.Options.AutoHyphenate = false; try { if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.MaximumShapes, StringResources.LoadingPublisherFile); } Microsoft.Office.Interop.Publisher.Document pbDoc = pbApp.Open(pubFilePath, false, false, PbSaveOptions.pbDoNotSaveChanges); #region | get total shapes count | foreach (Microsoft.Office.Interop.Publisher.Page page in pbDoc.MasterPages) { foreach (Microsoft.Office.Interop.Publisher.Shape shape in page.Shapes) { pub2xml.api.Processor.MaximumShapes++; } } foreach (Microsoft.Office.Interop.Publisher.Page page in pbDoc.Pages) { foreach (Microsoft.Office.Interop.Publisher.Shape shape in page.Shapes) { pub2xml.api.Processor.MaximumShapes++; } } #endregion try { #region | MasterPages | foreach (Microsoft.Office.Interop.Publisher.Page page in pbDoc.MasterPages) { foreach (Microsoft.Office.Interop.Publisher.Shape shape in page.Shapes) { pub2xml.api.Processor.CurrentIndex++; if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.CurrentIndex, StringResources.BuildingShape + ": " + shape.ID + ", " + shape.Name + "..."); } try { List <Structures.Core.TextFrame> tfs = setTextFramesFromShape(shape, imagePath, settings); if (tfs.Count > 0) { ep.textFrames.AddRange(tfs); } } catch (Exception ex) { throw ex; } } } #endregion #region | Pages | foreach (Microsoft.Office.Interop.Publisher.Page page in pbDoc.Pages) { foreach (Microsoft.Office.Interop.Publisher.Shape shape in page.Shapes) { pub2xml.api.Processor.CurrentIndex++; if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.CurrentIndex, StringResources.BuildingShape + ": " + shape.ID + ", " + shape.Name + "..."); } try { List <Structures.Core.TextFrame> tfs = setTextFramesFromShape(shape, imagePath, settings); if (tfs.Count > 0) { ep.textFrames.AddRange(tfs); } } catch (Exception ex) { throw ex; } if (pub2xml.api.Processor.CurrentIndex % 100 == 0) { if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.CurrentIndex, StringResources.SavingChanges); } pbDoc.Save(); } } } #endregion if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.MaximumShapes, StringResources.ApplyingInternalFontStyles); } #region | apply internal font information | Cache.settings.FontFormatTags.ForEach(a => { pbDoc.Find.FindText = "<" + a.name + ">"; pbDoc.Find.ReplaceScope = PbReplaceScope.pbReplaceScopeAll; pbDoc.Find.ReplaceWithText = ""; pbDoc.Find.Execute(); pbDoc.Find.FindText = "</" + a.name + ">"; pbDoc.Find.ReplaceScope = PbReplaceScope.pbReplaceScopeAll; pbDoc.Find.ReplaceWithText = ""; pbDoc.Find.Execute(); }); #endregion success = true; } catch (Exception ex) { throw ex; } finally { if (success) { if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.MaximumShapes, StringResources.SavingPublisherFile); } pbDoc.Save(); #region | create pdf | if (settings.ImportCreatePdfFile) { if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.MaximumShapes, StringResources.SavingPDFFile); } pbDoc.ExportAsFixedFormat(PbFixedFormatType.pbFixedFormatTypePDF, pubFilePath + Constants.pub2xmlPDFAfterImportExtension); } #endregion } pbDoc.Close(); pbDoc = null; } } catch (Exception ex) { throw ex; } finally { pbApp = null; GC.Collect(); Process[] Processes = Process.GetProcessesByName("MSPUB"); foreach (Process p in Processes) { if (p.MainWindowTitle.Trim() == "") { p.Kill(); } } } return(success); }
private List <Structures.Core.TextFrame> getImageFramesFromShape(Shape shape, SettingsCore settings, string imagePath, string pubFileName) { List <Structures.Core.TextFrame> tfs = new List <Structures.Core.TextFrame>(); if ((shape.Type == PbShapeType.pbPicture //|| shape.Type == PbShapeType.pbBarCodePictureHolder || shape.Type == PbShapeType.pbLinkedPicture) && settings.ExportPictures) { string imageFileName = "#" + (shape.PictureFormat.Filename.Trim() != string.Empty ? Path.GetFileName(shape.PictureFormat.Filename) : string.Empty); Structures.Core.TextFrame tf = new Structures.Core.TextFrame(); tf.shapeId = shape.ID; tf.shapeName = shape.Name; tf.shapeType = shape.Type.ToString(); tf.tableColumn = string.Empty; tf.tableRow = string.Empty; tf.paragraph = 1; tf.text = string.Empty; tf.imageName = pubFileName + "." + shape.ID.ToString() + "." + imageFileName + ".png"; string ext = string.Empty; try { if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.CurrentIndex, StringResources.ParsingShape + ": " + shape.ID + ", " + shape.Name + "... " + StringResources.SavingImage + ": " + imageFileName); } shape.Shadow.Visible = Microsoft.Office.Core.MsoTriState.msoFalse; shape.Shadow.OffsetX = 0; shape.Shadow.OffsetY = 0; shape.Shadow.Obscured = Microsoft.Office.Core.MsoTriState.msoFalse; shape.ScaleHeight(1f, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoScaleFrom.msoScaleFromTopLeft); shape.ScaleWidth(1f, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoScaleFrom.msoScaleFromTopLeft); shape.SetShapesDefaultProperties(); shape.SaveAsPicture(Path.Combine(imagePath, tf.imageName), PbPictureResolution.pbPictureResolutionDefault); tfs.Add(tf); } catch (Exception ex) { try { tf.message = StringResources.Picture + ": " + shape.ID + (imageFileName.Trim() != string.Empty ? imageFileName : string.Empty) + "\r\n" + ex.Message; pub2xml.api.Processor.ProcessingErrors.Add(tf); } catch (Exception ex1) { Trace.WriteLine(ex1.Message); } } } return(tfs); }
private List <Structures.Core.TextFrame> getTextFramesFromTableFrame(Shape shape, SettingsCore settings, string pubFileName) { List <Structures.Core.TextFrame> tfs = new List <Structures.Core.TextFrame>(); #region | HasTable | if (shape.HasTable == Microsoft.Office.Core.MsoTriState.msoTrue) { foreach (Microsoft.Office.Interop.Publisher.Cell cl in shape.Table.Cells) { if (cl.HasText) { if (!cl.TextRange.Text.Trim().StartsWith(Structures.Constants.pub2xml)) { if (settings.ExportText) { List <string> paragraphsText = getParagraphsText(cl.TextRange, settings.ExportMarkupInternalFontEffects); for (int i = 0; i < paragraphsText.Count; i++) { if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.CurrentIndex, StringResources.ParsingShape + ": " + shape.ID + ", " + shape.Name + "... " + StringResources.Paragraph + ": " + (i + 1).ToString() + " (" + StringResources.TableRow + ": " + cl.Row.ToString() + ", " + StringResources.Column + ": " + cl.Column.ToString() + ")"); } Structures.Core.TextFrame tf = new Structures.Core.TextFrame(); tf.shapeId = shape.ID; tf.shapeName = shape.Name; tf.shapeType = shape.Type.ToString(); tf.tableColumn = cl.Column.ToString(); tf.tableRow = cl.Row.ToString(); tf.paragraph = (i + 1); tf.text = (string)paragraphsText[i].Clone(); tfs.Add(tf); } cl.TextRange.Text = Structures.Constants.pub2xml + (settings.ExportPseudoTranslateFile ? getPseudoTranslatedText(cl.TextRange.Text, settings.PseudoTranslateItems) : cl.TextRange.Text); } } } } } #endregion return(tfs); }
private List <Structures.Core.TextFrame> setTextFramesFromTextFrame(Shape shape, SettingsCore settings) { List <Structures.Core.TextFrame> tfs_updated = new List <Structures.Core.TextFrame>(); #region | HasTextFrame | if (shape.HasTextFrame == Microsoft.Office.Core.MsoTriState.msoTrue) { if (shape.TextFrame.HasText == Microsoft.Office.Core.MsoTriState.msoTrue) { if (settings.ImportText) { List <Structures.Core.TextFrame> tf_paragraphs = new List <Structures.Core.TextFrame>(); if (pub2xml.api.Processor.FramesDictoinary.ContainsKey(shape.ID)) { foreach (Structures.Core.TextFrame tf in pub2xml.api.Processor.FramesDictoinary[shape.ID]) { if (shape.ID == tf.shapeId) { tf_paragraphs.Add(tf); } } if (tf_paragraphs.Count > 0) { if (tf_paragraphs.Count == shape.TextFrame.Story.TextRange.ParagraphsCount) { int paragraphsCount = shape.TextFrame.Story.TextRange.ParagraphsCount; List <ParagraphFormat> pfs = new List <ParagraphFormat>(); List <Font> fts = new List <Font>(); for (int i = paragraphsCount; i > 0; i--) { TextRange tr = shape.TextFrame.Story.TextRange.Paragraphs(i); fts.Add(tr.Font.Duplicate()); pfs.Add(tr.ParagraphFormat.Duplicate()); } pfs.Reverse(); fts.Reverse(); for (int i = paragraphsCount; i > 0; i--) { if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.CurrentIndex, StringResources.BuildingShape + ": " + shape.ID + ", " + shape.Name + "... " + StringResources.Paragraph + ": " + i.ToString()); } TextRange tr = shape.TextFrame.Story.TextRange.Paragraphs(i); Structures.Core.TextFrame tf = tf_paragraphs[(i - 1)]; tr.Text = string.Empty; string rangeText = tf.text.Replace("<r/>", "\r").Replace("<n/>", "\n"); tr.Text = rangeText; setTaggedText(tr); tr.Font = fts[(i - 1)]; tr.ParagraphFormat = pfs[(i - 1)]; } } else { throw new Exception(StringResources.TheParagraphCountsAreDifferentForShapeId + ": " + shape.ID.ToString()); } } } } } } #endregion return(tfs_updated); }
private List <Structures.Core.TextFrame> setTextFramesFromShape(Shape shape, string imagePath, SettingsCore settings) { List <Structures.Core.TextFrame> tfs_updated = new List <Structures.Core.TextFrame>(); if ((shape.Type == PbShapeType.pbPicture //|| shape.Type == PbShapeType.pbBarCodePictureHolder || shape.Type == PbShapeType.pbLinkedPicture) && settings.ImportPictures) { if (Directory.Exists(imagePath)) { tfs_updated.AddRange(setImageFramesFromShape(shape, imagePath, settings)); } } else { #region | HasTextFrame | if (shape.HasTextFrame == Microsoft.Office.Core.MsoTriState.msoTrue) { tfs_updated.AddRange(setTextFramesFromTextFrame(shape, settings)); } #endregion #region | HasTable | if (shape.HasTable == Microsoft.Office.Core.MsoTriState.msoTrue) { if (shape.Table.Cells.Count > 0) { tfs_updated.AddRange(setTextFramesFromTableFrame(shape, settings)); } } #endregion #region | GroupItems.Count > 0 | if (shape.Type == PbShapeType.pbGroup && shape.GroupItems.Count > 0) { foreach (Microsoft.Office.Interop.Publisher.Shape _shape in shape.GroupItems) { if ((shape.Type == PbShapeType.pbPicture //|| shape.Type == PbShapeType.pbBarCodePictureHolder || shape.Type == PbShapeType.pbLinkedPicture) && settings.ImportPictures) { if (Directory.Exists(imagePath)) { tfs_updated.AddRange(setImageFramesFromShape(_shape, imagePath, settings)); } } else { #region | HasTextFrame | if (_shape.HasTextFrame == Microsoft.Office.Core.MsoTriState.msoTrue) { tfs_updated.AddRange(setTextFramesFromTextFrame(_shape, settings)); } #endregion #region | HasTable | if (_shape.HasTable == Microsoft.Office.Core.MsoTriState.msoTrue) { tfs_updated.AddRange(setTextFramesFromTableFrame(_shape, settings)); } #endregion } } } #endregion } return(tfs_updated); }
private List <Structures.Core.TextFrame> getTextFramesFromShape(Shape shape, SettingsCore settings, string imagePath, string pubFileName) { List <Structures.Core.TextFrame> tfs = new List <Structures.Core.TextFrame>(); try { if ((shape.Type == PbShapeType.pbPicture || shape.Type == PbShapeType.pbLinkedPicture) && settings.ExportPictures) { if (!Directory.Exists(imagePath)) { Directory.CreateDirectory(imagePath); } tfs.AddRange(getImageFramesFromShape(shape, settings, imagePath, pubFileName)); } else { #region | HasTextFrame | if (shape.HasTextFrame == Microsoft.Office.Core.MsoTriState.msoTrue) { tfs.AddRange(getTextFramesFromTextFrame(shape, settings, pubFileName)); } #endregion #region | HasTable | if (shape.HasTable == Microsoft.Office.Core.MsoTriState.msoTrue) { if (shape.Table.Cells.Count > 0) { tfs.AddRange(getTextFramesFromTableFrame(shape, settings, pubFileName)); } } #endregion #region | GroupItems.Count > 0 | if (shape.Type == PbShapeType.pbGroup && shape.GroupItems.Count > 0) { foreach (Shape _shape in shape.GroupItems) { if ((shape.Type == PbShapeType.pbPicture || shape.Type == PbShapeType.pbLinkedPicture) && settings.ExportPictures) { if (!Directory.Exists(imagePath)) { Directory.CreateDirectory(imagePath); } tfs.AddRange(getImageFramesFromShape(_shape, settings, imagePath, pubFileName)); } else { #region | HasTextFrame | if (_shape.HasTextFrame == Microsoft.Office.Core.MsoTriState.msoTrue) { tfs.AddRange(getTextFramesFromTextFrame(_shape, settings, pubFileName)); } #endregion #region | HasTable | if (_shape.HasTable == Microsoft.Office.Core.MsoTriState.msoTrue) { tfs.AddRange(getTextFramesFromTableFrame(_shape, settings, pubFileName)); } #endregion } } } #endregion } } catch (Exception ex) { throw ex; } return(tfs); }