예제 #1
0
        /// <summary>
        /// Get each paragraph xml element's attributes to update their style.
        /// </summary>
        private void UpdateElementColor(InDesign.XMLElement p_element)
        {
            InDesign.Paragraph  paragraph = null;
            InDesign.XMLElement element   = null;

            if (p_element.Paragraphs.Count > 0)
            {
                element = p_element;
            }
            else if (((InDesign.XMLElement)p_element.Parent).Paragraphs.Count > 0)
            {
                element = (InDesign.XMLElement)p_element.Parent;
            }

            if (element != null)
            {
                InDesign.Color color = null;

                for (int ii = 0; ii < element.Paragraphs.Count; ii++)
                {
                    if (ii == 0)
                    {
                        paragraph = (InDesign.Paragraph)element.Paragraphs.FirstItem();
                    }
                    else
                    {
                        paragraph = (InDesign.Paragraph)element.Paragraphs.NextItem(paragraph);
                    }

                    color = UpdateParagraphColor(paragraph, color);
                }
            }
        }
예제 #2
0
        private void CheckByChar(InDesign.Paragraph paragraph)
        {
            int count = paragraph.Characters.Count;

            InDesign.Character cha = null;

            for (int i = 0; i < count; i++)
            {
                if (i == 0)
                {
                    cha = (InDesign.Character)paragraph.Characters.FirstItem();
                }
                else
                {
                    cha = (InDesign.Character)paragraph.Characters.NextItem(cha);
                }

                InDesign.Color color = (InDesign.Color)cha.FillColor;

                if (color != null && !color.Name.StartsWith(S_COLOR_PRE))
                {
                    InDesign.Character nextcha = null;
                    InDesign.Character precha  = null;
                    try
                    {
                        nextcha = (InDesign.Character)paragraph.Characters.NextItem(cha);
                        while (nextcha != null && nextcha.FillColor != null &&
                               !((InDesign.Color)nextcha.FillColor).Name.StartsWith(S_COLOR_PRE))
                        {
                            nextcha = (InDesign.Character)paragraph.Characters.NextItem(nextcha);
                        }
                    }
                    catch { }
                    try
                    {
                        precha = (InDesign.Character)paragraph.Characters.PreviousItem(cha);
                        while (precha != null && precha.FillColor != null &&
                               !((InDesign.Color)precha.FillColor).Name.StartsWith(S_COLOR_PRE))
                        {
                            precha = (InDesign.Character)paragraph.Characters.PreviousItem(precha);
                        }
                    }
                    catch { }

                    if (nextcha != null && nextcha.FillColor != null &&
                        ((InDesign.Color)nextcha.FillColor).Name.StartsWith(S_COLOR_PRE))
                    {
                        cha.FillColor = nextcha.FillColor;
                    }
                    else if (precha != null && precha.FillColor != null &&
                             ((InDesign.Color)precha.FillColor).Name.StartsWith(S_COLOR_PRE))
                    {
                        cha.FillColor = precha.FillColor;
                    }
                }
            }
        }
예제 #3
0
        private void UpdateTableStyle(InDesign.Paragraph p_paragraph)
        {
            InDesign.Table     table = null;
            InDesign.Cell      cell  = null;
            InDesign.Paragraph p     = null;
            // update tables styles if paragraph has tables.
            for (int t = 0; t < p_paragraph.Tables.Count; t++)
            {
                if (t == 0)
                {
                    table = (InDesign.Table)p_paragraph.Tables.FirstItem();
                }
                else
                {
                    table = (InDesign.Table)p_paragraph.Tables.NextItem(table);
                }

                // update cells one by one
                for (int i = 0; i < table.Cells.Count; i++)
                {
                    if (i == 0)
                    {
                        cell = (InDesign.Cell)table.Cells.FirstItem();
                    }
                    else
                    {
                        cell = (InDesign.Cell)table.Cells.NextItem(cell);
                    }

                    InDesign.Color      color = null;
                    InDesign.Paragraphs ps    = cell.Paragraphs;

                    for (int j = 0; j < ps.Count; j++)
                    {
                        if (j == 0)
                        {
                            p = (InDesign.Paragraph)ps.FirstItem();
                        }
                        else
                        {
                            p = (InDesign.Paragraph)ps.NextItem(p);
                        }

                        color = UpdateParagraphColor(p, color);
                    }
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Get each paragraph xml element's attributes to update their style.
        /// </summary>
        private void UpdateElementStyle(InDesign.XMLElement p_element)
        {
            InDesign.XMLAttribute xmlAttr   = null;
            InDesign.Paragraph    paragraph = null;
            InDesign.Font         font      = null;
            string fontfamily    = null;
            string fontstylename = null;

            if (p_element.Paragraphs.Count > 0)
            {
                paragraph = (InDesign.Paragraph)p_element.Paragraphs.FirstItem();

                for (int i = 0; i < p_element.XMLAttributes.Count; i++)
                {
                    if (i == 0)
                    {
                        xmlAttr = (InDesign.XMLAttribute)p_element.XMLAttributes.FirstItem();
                    }
                    else
                    {
                        xmlAttr = (InDesign.XMLAttribute)p_element.XMLAttributes.NextItem(xmlAttr);
                    }

                    if (FONT_FAMILY_ATTRIBUTE.Equals(xmlAttr.Name))
                    {
                        fontfamily = xmlAttr.Value;
                    }

                    if (FONT_STYLE_ATTRIBUTE.Equals(xmlAttr.Name))
                    {
                        fontstylename = xmlAttr.Value;
                    }

                    if (FONT_SIZE_ATTRIBUTE.Equals(xmlAttr.Name))
                    {
                        paragraph.PointSize = xmlAttr.Value;
                    }
                }

                font = GetProperFont(fontfamily, fontstylename);
                if (font != null)
                {
                    paragraph.AppliedFont = font;
                }
            }
        }
예제 #5
0
        private InDesign.Color UpdateParagraphColor(InDesign.Paragraph paragraph, InDesign.Color color)
        {
            int wordsCount = paragraph.Words.Count;

            InDesign.Word lastWord = null;
            ContentColor  lastcc   = null;

            for (int i = 0; i < wordsCount; i++)
            {
                InDesign.Word word = null;
                if (i == 0)
                {
                    word = (InDesign.Word)paragraph.Words.FirstItem();
                }
                else
                {
                    word = (InDesign.Word)paragraph.Words.NextItem(lastWord);
                }

                if (lastWord != null && lastcc != null)
                {
                    lastWord.Contents  = lastcc.Content;
                    lastWord.FillColor = lastcc.Color;
                }

                string       content = word.Contents.ToString();
                ContentColor cc      = DetermineColor(content, color);
                color    = cc.Color;
                lastWord = word;
                lastcc   = cc;
            }

            if (lastWord != null && lastcc != null)
            {
                lastWord.Contents  = lastcc.Content;
                lastWord.FillColor = lastcc.Color;
            }

            //CheckByChar(paragraph);

            UpdateTableStyle(paragraph);

            return(color);
        }
예제 #6
0
        /// <summary>
        /// Mark up the paragraph and style of indd file with special xml tags.
        /// </summary>
        private void MarkupInddParagraph(InDesign.XMLElement p_parentElm, InDesign.Paragraph p_paragraph)
        {
            InDesign.XMLElement xmlElement = null;
            InDesign.Font       font       = null;

            // Add a new xml element which will be used to mark up a paragraph.
            InDesign.XMLElements subElements = p_parentElm.XMLElements;
            xmlElement = subElements.Add(INDD_PARAGRAPH_TAG, INDD_XMLCONTENT);

            // Get the paragraph's attributes to be translated.
            // For example
            // FontFamily:  Times New Roman
            // PointSize: 12
            font = (InDesign.Font)p_paragraph.AppliedFont;
            xmlElement.XMLAttributes.Add(FONT_FAMILY_ATTRIBUTE, font.FontFamily);
            xmlElement.XMLAttributes.Add(FONT_STYLE_ATTRIBUTE, p_paragraph.FontStyle);
            xmlElement.XMLAttributes.Add(FONT_SIZE_ATTRIBUTE, p_paragraph.PointSize.ToString());

            // Markup the paragraph with xml element
            // so that it can be exported into xml file.
            p_paragraph.Markup(xmlElement);
        }
예제 #7
0
        /// <summary>
        /// Mark up the story and style of indd file with special xml tags.
        /// </summary>
        private void MarkupInddStory(InDesign.XMLElement p_parentElm, InDesign.Story p_story)
        {
            ArrayList paraList = new ArrayList();

            InDesign.Paragraph   paragraph   = null;
            InDesign.XMLElement  xmlElement  = null;
            InDesign.XMLElements subElements = null;

            subElements = p_parentElm.XMLElements;
            xmlElement  = subElements.Add(INDD_STORY_TAG, INDD_XMLCONTENT);
            p_story.Markup(xmlElement);

            // Get all paragraphes.
            for (int i = 0; i < p_story.Paragraphs.Count; i++)
            {
                if (i == 0)
                {
                    paragraph = (InDesign.Paragraph)p_story.Paragraphs.FirstItem();
                }
                else
                {
                    paragraph = (InDesign.Paragraph)p_story.Paragraphs.NextItem(paragraph);
                }

                paraList.Add(paragraph);
            }

            // Mark up each paragraph.
            foreach (InDesign.Paragraph eachparagraph in paraList)
            {
                if (eachparagraph.Contents.ToString().Trim().Length > 0)
                {
                    MarkupInddParagraph(xmlElement, eachparagraph);
                }
            }
        }