#!/usr/bin/env python
from rtfng.utils import RTFTestCase
from rtfng.Elements import Document, StyleSheet
from rtfng.PropertySets import ShadingPropertySet, TextPropertySet
from rtfng.Styles import TextStyle

from rtfng.document.character import B, I, U, TEXT, Text
from rtfng.document.section import Section
from rtfng.document.paragraph import Paragraph

class CharacterTestCase(RTFTestCase):

    def make_charStyleOverride():
        doc, section, styles = RTFTestCase.initializeDoc()
        p = Paragraph()
        p.append('This is a standard paragraph with the default style.')
        p = Paragraph()
        p.append('It is also possible to manully override a style. ',
                  'This is a change of just the font ',
                  TEXT('size', size=48),
                  ' an this is for just the font ',
                  TEXT('typeface', font=styles.Fonts.Impact) ,
                  '.')
        section.append(p)
        return doc
    make_charStyleOverride = staticmethod(make_charStyleOverride)

    def test_charStyleOverride(self):
        self.doTest()

    def make_charColours():
        doc, section, styles = RTFTestCase.initializeDoc()
        section.append('This example test changing the colour of fonts.')
        # Text properties can be specified in two ways, either a text object
        # can have its text properties specified via the TextPropertySet
        # object, or by passing the colour parameter as a style.
        red = TextPropertySet(colour=styles.Colours.Red)
        green = TextPropertySet(colour=styles.Colours.Green)
        blue = TextPropertySet(colour=styles.Colours.Blue)
        yellow = TextPropertySet(colour=styles.Colours.Yellow)
        p = Paragraph()
        p.append('This next word should be in ')
        p.append(Text('red', red))
        p.append(', while the following should be in their respective ')
        p.append('colours: ', Text('blue ', blue), Text('green ', green))
        p.append('and ', TEXT('yellow', colour=styles.Colours.Yellow), '.')
        # When specifying colours it is important to use the colours from the
        # style sheet supplied with the document and not the StandardColours
        # object each document get its own copy of the stylesheet so that
        # changes can be made on a document by document basis without mucking
        # up other documents that might be based on the same basic stylesheet.
        section.append(p)
        return doc
    make_charColours = staticmethod(make_charColours)

    def test_charColours(self):
        self.doTest()

    def make_charUnicode():
        doc, section, styles = RTFTestCase.initializeDoc()
        section.append('This tests unicode.')
        
        p = Paragraph()
        p.append(u'32\u00B0 Fahrenheit is 0\u00B0 Celsuis')
        section.append(p)
        
        p = Paragraph()
        p.append(u'Henry \u2163 is Henry IV in unicode.')
        section.append(p)
        

        return doc
    make_charUnicode = staticmethod(make_charUnicode)

    def test_charUnicode(self):
        self.doTest()


class CharacterAPITestCase(RTFTestCase):

    def test_text(self):
        t = Text()
        t = Text('abc')
        style = StyleSheet()
        normalText = TextStyle(TextPropertySet(style.Fonts.Arial, 22))
        blue = TextPropertySet(colour=style.Colours.Blue)
        shading = ShadingPropertySet()
        t = Text(normalText, blue, shading, 'abc')

    def test_textConvenience(self):
        t = TEXT('abc')
        t = TEXT('abc', 'def')

        t = B('abc')
        t = B('abc', 'def')

        t = I('abc')
        t = I('abc', 'def')

        t = U('abc')
        t = U('abc', 'def')


@@ -165,16 +165,38 @@
 pertySet
+, ParagraphPropertySet
 %0Afrom rt
@@ -3685,24 +3685,756 @@
    t = U('abc', 'def')%0A%0A
+    def test_TextPropertySet(self):%0A        style = StyleSheet()%0A        blue = TextPropertySet(colour=style.Colours.Blue)%0A        red = blue.Copy()%0A        red.colour = style.Colours.Red%0A        %0A        # Confirm that the copies are independent objects.%0A        assert blue.colour == style.Colours.Blue%0A        assert red.colour == style.Colours.Red%0A%0A    def test_ParagraphPropertySet(self):%0A        left = ParagraphPropertySet(ParagraphPropertySet.LEFT)%0A        center = left.Copy()%0A        center.Alignment = ParagraphPropertySet.CENTER%0A        %0A        # Confirm that the copies are independent objects.%0A        assert left.Alignment == ParagraphPropertySet.LEFT%0A        assert center.Alignment == ParagraphPropertySet.CENTER%0A%0A

add tests for Copy in TextPropertySet and ParagraphPropertySet