コード例 #1
0
ファイル: XamlToRtfWriter.cs プロジェクト: sjyanxin/WPFSource
            // Helper for IXamlContentHandler.StartElement.
            private DocumentNode CreateDocumentNode(ConverterState converterState, DocumentNodeType documentNodeType, DocumentNode dnTop, XamlTag xamlTag)
            {
                DocumentNode documentNode = new DocumentNode(documentNodeType); 
                if (dnTop != null)
                { 
                    documentNode.InheritFormatState(dnTop.FormatState); 
                }
 
                // Handle implicit formatting properties.
                switch (xamlTag)
                {
                    case XamlTag.XTBold: 
                        documentNode.FormatState.Bold = true;
                        break; 
 
                    case XamlTag.XTHyperlink:
                        { 
                            long lColor = 0;
                            documentNode.FormatState.UL = ULState.ULNormal;
                            if (XamlParserHelper.ConvertToColor(converterState, "#FF0000FF", ref lColor))
                            { 
                                documentNode.FormatState.CF = lColor;
                            } 
                        } 
                        break;
 
                    case XamlTag.XTItalic:
                        documentNode.FormatState.Italic = true;
                        break;
 
                    case XamlTag.XTUnderline:
                        documentNode.FormatState.UL = ULState.ULNormal; 
                        break; 

                    case XamlTag.XTList: 
                        documentNode.FormatState.Marker = MarkerStyle.MarkerBullet;
                        documentNode.FormatState.StartIndex = 1;

                        // Set the default left margin for a list. 
                        documentNode.FormatState.LI = 720;
                        break; 
                } 

                return documentNode; 
            }
コード例 #2
0
ファイル: XamlToRtfWriter.cs プロジェクト: sjyanxin/WPFSource
            XamlToRtfError IXamlContentHandler.Characters(string characters)
            { 
                XamlToRtfError xamlToRtfError = XamlToRtfError.None;
 
                ConverterState converterState = _writer.ConverterState; 
                DocumentNodeArray dna = converterState.DocumentNodeArray;
                DocumentNode dnTop = dna.TopPending(); 
                DocumentNode dn;

                int index = 0;
 
                while (xamlToRtfError == XamlToRtfError.None && index < characters.Length)
                { 
                    // Move past opening CRLF 
                    while (index < characters.Length && IsNewLine(characters[index]))
                    { 
                        index++;
                    }

                    int end = index; 

                    while (end < characters.Length && !IsNewLine(characters[end])) 
                    { 
                        end++;
                    } 

                    if (index != end)
                    {
                        string newCharacters = characters.Substring(index, end - index); 

                        dn = new DocumentNode(DocumentNodeType.dnText); 
                        if (dnTop != null) 
                        {
                            dn.InheritFormatState(dnTop.FormatState); 
                        }

                        dna.Push(dn);
                        dn.IsPending = false; 

                        if (xamlToRtfError == XamlToRtfError.None) 
                        { 
                            FontTableEntry e = converterState.FontTable.FindEntryByIndex((int)dn.FormatState.Font);
                            int cp = (e == null) ? 1252 : e.CodePage; 
                            XamlParserHelper.AppendRTFText(dn.Content, newCharacters, cp);
                        }
                    }
 
                    index = end;
                } 
 
                return xamlToRtfError;
            }