Browse Source

映射textField
textFieldExpression类型可能为DatabaseField、FormulaField
字体样式:粗体、斜体、下划线、删除线

sunyj 8 years ago
parent
commit
590310078f
1 changed files with 104 additions and 1 deletions
  1. 104 1
      src/main/resources/crystal2jasper.xsl

+ 104 - 1
src/main/resources/crystal2jasper.xsl

@@ -114,18 +114,43 @@
 											<xsl:variable name="textAlignment"
 												select="CommonProperties/HorizontalAlign/@value"></xsl:variable>
 											<!-- horizontal align -->
-											<xsl:attribute name="textAlignment">
+											<xsl:if test="$textAlignment">
+												<xsl:attribute name="textAlignment">
 													<xsl:choose>
 														<xsl:when test="$textAlignment='1'">Left</xsl:when>
 														<xsl:when test="$textAlignment='2'">Center</xsl:when>
 														<xsl:when test="$textAlignment='3'">Right</xsl:when>
 													</xsl:choose>
 												</xsl:attribute>
+											</xsl:if>
 											<!-- font -->
 											<font fontName="Microsoft YaHei UI">
 												<!-- font size -->
 												<xsl:attribute name="size"><xsl:value-of
 													select="round(Element/Element/FontProperties/FontSize/@value div $positionRate * 0.75)" /></xsl:attribute>
+												<!-- font style -->
+												<xsl:variable name="fontStyle"
+													select="Element/Element/FontProperties/FontStyle/@value"></xsl:variable>
+												<xsl:choose>
+													<xsl:when test="$fontStyle mod 4 ='1'">
+														<xsl:attribute name="isBold">true</xsl:attribute>
+													</xsl:when>
+													<xsl:when test="$fontStyle mod 4 ='2'">
+														<xsl:attribute name="isItalic">true</xsl:attribute>
+													</xsl:when>
+													<xsl:when test="$fontStyle mod 4 ='3'">
+														<xsl:attribute name="isBold">true</xsl:attribute>
+														<xsl:attribute name="isItalic">true</xsl:attribute>
+													</xsl:when>
+												</xsl:choose>
+												<!-- font underline -->
+												<xsl:if test="Element/Element/FontProperties/Underline/@value">
+													<xsl:attribute name="isUnderline">true</xsl:attribute>
+												</xsl:if>
+												<!-- font strikethrough -->
+												<xsl:if test="Element/Element/FontProperties/Strikeout/@value">
+													<xsl:attribute name="isStrikeThrough">true</xsl:attribute>
+												</xsl:if>
 											</font>
 										</textElement>
 										<text>
@@ -133,6 +158,84 @@
 										</text>
 									</staticText>
 								</xsl:when>
+								<!-- textField -->
+								<xsl:when test="$type='FieldElement'">
+									<textField isBlankWhenNull="true">
+										<reportElement mode="Opaque">
+											<!-- position -->
+											<xsl:attribute name="x">
+												<xsl:value-of select="round(@x_position div $positionRate)" />
+											</xsl:attribute>
+											<xsl:attribute name="y">
+												<xsl:value-of select="round(@y_position div $positionRate)" />
+											</xsl:attribute>
+											<xsl:attribute name="width">
+												<xsl:value-of select="round(@width div $positionRate)" />
+											</xsl:attribute>
+											<xsl:attribute name="height">
+												<xsl:value-of select="round(@height div $positionRate)" />
+											</xsl:attribute>
+										</reportElement>
+										<textElement verticalAlignment="Middle">
+											<xsl:variable name="textAlignment"
+												select="CommonProperties/HorizontalAlign/@value"></xsl:variable>
+											<!-- horizontal align -->
+											<xsl:if test="$textAlignment">
+												<xsl:attribute name="textAlignment">
+													<xsl:choose>
+														<xsl:when test="$textAlignment='1'">Left</xsl:when>
+														<xsl:when test="$textAlignment='2'">Center</xsl:when>
+														<xsl:when test="$textAlignment='3'">Right</xsl:when>
+													</xsl:choose>
+												</xsl:attribute>
+											</xsl:if>
+											<!-- font -->
+											<font fontName="Microsoft YaHei UI">
+												<!-- font size -->
+												<xsl:attribute name="size"><xsl:value-of
+													select="round(FontProperties/FontSize/@value div $positionRate * 0.75)" /></xsl:attribute>
+												<!-- font style -->
+												<xsl:variable name="fontStyle"
+													select="FontProperties/FontStyle/@value"></xsl:variable>
+												<xsl:choose>
+													<xsl:when test="$fontStyle mod 4 ='1'">
+														<xsl:attribute name="isBold">true</xsl:attribute>
+													</xsl:when>
+													<xsl:when test="$fontStyle mod 4 ='2'">
+														<xsl:attribute name="isItalic">true</xsl:attribute>
+													</xsl:when>
+													<xsl:when test="$fontStyle mod 4 ='3'">
+														<xsl:attribute name="isBold">true</xsl:attribute>
+														<xsl:attribute name="isItalic">true</xsl:attribute>
+													</xsl:when>
+												</xsl:choose>
+												<!-- font underline -->
+												<xsl:if test="FontProperties/Underline/@value">
+													<xsl:attribute name="isUnderline">true</xsl:attribute>
+												</xsl:if>
+												<!-- font strikethrough -->
+												<xsl:if test="FontProperties/Strikeout/@value">
+													<xsl:attribute name="isStrikeThrough">true</xsl:attribute>
+												</xsl:if>
+											</font>
+										</textElement>
+										<!-- textFieldExpression -->
+										<xsl:if test="Reference">
+											<xsl:variable name="type" select="Reference/@type"></xsl:variable>
+											<xsl:variable name="value" select="Reference/@value"></xsl:variable>
+											<textFieldExpression>
+												<xsl:choose>
+													<xsl:when test="$type='DatabaseField'">
+														$F{<xsl:value-of select="substring-after($value,'.')"></xsl:value-of>}
+													</xsl:when>
+													<xsl:when test="$type='FormulaField'">
+														<xsl:value-of select="$value"></xsl:value-of>
+													</xsl:when>
+												</xsl:choose>
+											</textFieldExpression>
+										</xsl:if>
+									</textField>
+								</xsl:when>
 							</xsl:choose>
 						</xsl:for-each>
 					</band>