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> 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> 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> 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> 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> 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); }