|
| 1 | + |
| 2 | +Run-properties |
| 3 | +============== |
| 4 | + |
| 5 | +Character formatting such as font typeface, size, bold, and italic are applied |
| 6 | +at the run level. |
| 7 | + |
| 8 | + |
| 9 | +Candidate protocol |
| 10 | +------------------ |
| 11 | + |
| 12 | +The following interactive session demonstrates the protocol for querying and |
| 13 | +applying run-level properties:: |
| 14 | + |
| 15 | + >>> run = p.add_run() |
| 16 | + >>> run.bold |
| 17 | + None |
| 18 | + >>> run.bold = True |
| 19 | + >>> run.bold |
| 20 | + True |
| 21 | + >>> run.bold = False |
| 22 | + >>> run.bold |
| 23 | + False |
| 24 | + >>> run.bold = None |
| 25 | + >>> run.bold |
| 26 | + None |
| 27 | + |
| 28 | + |
| 29 | +Acceptance tests |
| 30 | +---------------- |
| 31 | + |
| 32 | +:: |
| 33 | + |
| 34 | + Feature: Apply bold or italic to run |
| 35 | + In order to apply emphasis to a particular word or phrase in a paragraph |
| 36 | + As a python-docx developer |
| 37 | + I need a way to query and set bold and italic on a run |
| 38 | + |
| 39 | + Scenario: Apply bold to a run |
| 40 | + Given a run |
| 41 | + When I assign True to its bold property |
| 42 | + Then the run appears in bold typeface |
| 43 | + |
| 44 | + Scenario: Remove bold from a run |
| 45 | + Given a run having bold set on |
| 46 | + When I assign None to its bold property |
| 47 | + Then the run appears with its inherited bold setting |
| 48 | + |
| 49 | + Scenario: Set bold off unconditionally |
| 50 | + Given a run |
| 51 | + When I assign False to its bold property |
| 52 | + Then the run appears without bold regardless of its style hierarchy |
| 53 | + |
| 54 | + |
| 55 | +Specimen XML |
| 56 | +------------ |
| 57 | + |
| 58 | +.. highlight:: xml |
| 59 | + |
| 60 | +:: |
| 61 | + |
| 62 | + <w:r w:rsidRPr="00FA3070"> |
| 63 | + <w:rPr> |
| 64 | + <w:b/> |
| 65 | + <w:i/> |
| 66 | + <w:smallCaps/> |
| 67 | + <w:strike/> |
| 68 | + <w:sz w:val="28"/> |
| 69 | + <w:szCs w:val="28"/> |
| 70 | + <w:u w:val="single"/> |
| 71 | + </w:rPr> |
| 72 | + <w:t>bold, italic, small caps, strike, size, and underline, applied in |
| 73 | + reverse order but not to paragraph mark</w:t> |
| 74 | + </w:r> |
| 75 | + |
| 76 | + |
| 77 | +Schema excerpt |
| 78 | +-------------- |
| 79 | + |
| 80 | +.. highlight:: xml |
| 81 | + |
| 82 | +It appears the run properties may appear in any order and may appear multiple |
| 83 | +times each. Not sure what the semantics of that would be or why one would |
| 84 | +want to do it, but something to note. Word seems to place them in the order |
| 85 | +below when it writes the file.:: |
| 86 | + |
| 87 | + <xsd:complexType name="CT_R"> <!-- denormalized --> |
| 88 | + <xsd:sequence> |
| 89 | + <xsd:element name="rPr" type="CT_RPr" minOccurs="0"/> |
| 90 | + <xsd:group ref="EG_RunInnerContent" minOccurs="0" maxOccurs="unbounded"/> |
| 91 | + </xsd:sequence> |
| 92 | + <xsd:attribute name="rsidRPr" type="ST_LongHexNumber"/> |
| 93 | + <xsd:attribute name="rsidDel" type="ST_LongHexNumber"/> |
| 94 | + <xsd:attribute name="rsidR" type="ST_LongHexNumber"/> |
| 95 | + </xsd:complexType> |
| 96 | + |
| 97 | + <xsd:complexType name="CT_RPr"> |
| 98 | + <xsd:sequence> |
| 99 | + <xsd:group ref="EG_RPrContent" minOccurs="0"/> |
| 100 | + </xsd:sequence> |
| 101 | + </xsd:complexType> |
| 102 | + |
| 103 | + <xsd:group name="EG_RPrContent"> |
| 104 | + <xsd:sequence> |
| 105 | + <xsd:group ref="EG_RPrBase" minOccurs="0" maxOccurs="unbounded"/> |
| 106 | + <xsd:element name="rPrChange" type="CT_RPrChange" minOccurs="0"/> |
| 107 | + </xsd:sequence> |
| 108 | + </xsd:group> |
| 109 | + |
| 110 | + <xsd:group name="EG_RPrBase"> |
| 111 | + <xsd:choice> |
| 112 | + <xsd:element name="rStyle" type="CT_String"/> |
| 113 | + <xsd:element name="rFonts" type="CT_Fonts"/> |
| 114 | + <xsd:element name="b" type="CT_OnOff"/> |
| 115 | + <xsd:element name="bCs" type="CT_OnOff"/> |
| 116 | + <xsd:element name="i" type="CT_OnOff"/> |
| 117 | + <xsd:element name="iCs" type="CT_OnOff"/> |
| 118 | + <xsd:element name="caps" type="CT_OnOff"/> |
| 119 | + <xsd:element name="smallCaps" type="CT_OnOff"/> |
| 120 | + <xsd:element name="strike" type="CT_OnOff"/> |
| 121 | + <xsd:element name="dstrike" type="CT_OnOff"/> |
| 122 | + <xsd:element name="outline" type="CT_OnOff"/> |
| 123 | + <xsd:element name="shadow" type="CT_OnOff"/> |
| 124 | + <xsd:element name="emboss" type="CT_OnOff"/> |
| 125 | + <xsd:element name="imprint" type="CT_OnOff"/> |
| 126 | + <xsd:element name="noProof" type="CT_OnOff"/> |
| 127 | + <xsd:element name="snapToGrid" type="CT_OnOff"/> |
| 128 | + <xsd:element name="vanish" type="CT_OnOff"/> |
| 129 | + <xsd:element name="webHidden" type="CT_OnOff"/> |
| 130 | + <xsd:element name="color" type="CT_Color"/> |
| 131 | + <xsd:element name="spacing" type="CT_SignedTwipsMeasure"/> |
| 132 | + <xsd:element name="w" type="CT_TextScale"/> |
| 133 | + <xsd:element name="kern" type="CT_HpsMeasure"/> |
| 134 | + <xsd:element name="position" type="CT_SignedHpsMeasure"/> |
| 135 | + <xsd:element name="sz" type="CT_HpsMeasure"/> |
| 136 | + <xsd:element name="szCs" type="CT_HpsMeasure"/> |
| 137 | + <xsd:element name="highlight" type="CT_Highlight"/> |
| 138 | + <xsd:element name="u" type="CT_Underline"/> |
| 139 | + <xsd:element name="effect" type="CT_TextEffect"/> |
| 140 | + <xsd:element name="bdr" type="CT_Border"/> |
| 141 | + <xsd:element name="shd" type="CT_Shd"/> |
| 142 | + <xsd:element name="fitText" type="CT_FitText"/> |
| 143 | + <xsd:element name="vertAlign" type="CT_VerticalAlignRun"/> |
| 144 | + <xsd:element name="rtl" type="CT_OnOff"/> |
| 145 | + <xsd:element name="cs" type="CT_OnOff"/> |
| 146 | + <xsd:element name="em" type="CT_Em"/> |
| 147 | + <xsd:element name="lang" type="CT_Language"/> |
| 148 | + <xsd:element name="eastAsianLayout" type="CT_EastAsianLayout"/> |
| 149 | + <xsd:element name="specVanish" type="CT_OnOff"/> |
| 150 | + <xsd:element name="oMath" type="CT_OnOff"/> |
| 151 | + </xsd:choice> |
| 152 | + </xsd:group> |
| 153 | + |
| 154 | + <xsd:complexType name="CT_OnOff"> |
| 155 | + <xsd:attribute name="val" type="s:ST_OnOff"/> |
| 156 | + </xsd:complexType> |
| 157 | + |
| 158 | + <xsd:simpleType name="ST_OnOff"> |
| 159 | + <xsd:union memberTypes="xsd:boolean ST_OnOff1"/> |
| 160 | + </xsd:simpleType> |
| 161 | + |
| 162 | + <xsd:simpleType name="ST_OnOff1"> |
| 163 | + <xsd:restriction base="xsd:string"> |
| 164 | + <xsd:enumeration value="on"/> |
| 165 | + <xsd:enumeration value="off"/> |
| 166 | + </xsd:restriction> |
| 167 | + </xsd:simpleType> |
| 168 | + |
| 169 | + |
| 170 | +Resources |
| 171 | +--------- |
| 172 | + |
| 173 | +* `WdBreakType Enumeration on MSDN`_ |
| 174 | +* `Range.InsertBreak Method (Word) on MSDN`_ |
| 175 | + |
| 176 | +.. _WdBreakType Enumeration on MSDN: |
| 177 | + http://msdn.microsoft.com/en-us/library/office/ff195905.aspx |
| 178 | + |
| 179 | +.. _Range.InsertBreak Method (Word) on MSDN: |
| 180 | + http://msdn.microsoft.com/en-us/library/office/ff835132.aspx |
0 commit comments