コード例 #1
0
        private static void ApplyIllustrationLayoutAttributes(AbstractRenderer renderer, PdfDictionary attributes)
        {
            Rectangle bbox = renderer.GetOccupiedArea().GetBBox();

            attributes.Put(PdfName.BBox, new PdfArray(bbox));
            UnitValue width = renderer.GetProperty <UnitValue>(Property.WIDTH);

            if (width != null && width.IsPointValue())
            {
                attributes.Put(PdfName.Width, new PdfNumber(width.GetValue()));
            }
            else
            {
                attributes.Put(PdfName.Width, new PdfNumber(bbox.GetWidth()));
            }
            UnitValue height = renderer.GetProperty <UnitValue>(Property.HEIGHT);

            if (height != null)
            {
                attributes.Put(PdfName.Height, new PdfNumber(height.GetValue()));
            }
            else
            {
                attributes.Put(PdfName.Height, new PdfNumber(bbox.GetHeight()));
            }
        }
コード例 #2
0
        private static void ApplyBlockLevelLayoutAttributes(String role, AbstractRenderer renderer, PdfDictionary
                                                            attributes)
        {
            UnitValue[] margins = new UnitValue[] { renderer.GetPropertyAsUnitValue(Property.MARGIN_TOP), renderer.GetPropertyAsUnitValue
                                                        (Property.MARGIN_BOTTOM), renderer.GetPropertyAsUnitValue(Property.MARGIN_LEFT), renderer.GetPropertyAsUnitValue
                                                        (Property.MARGIN_RIGHT) };
            int[] marginsOrder = new int[] { 0, 1, 2, 3 };
            //TODO set depending on writing direction
            UnitValue spaceBefore = margins[marginsOrder[0]];

            if (spaceBefore != null)
            {
                if (!spaceBefore.IsPointValue())
                {
                    ILog logger = LogManager.GetLogger(typeof(AccessibleAttributesApplier));
                    logger.Error(MessageFormatUtil.Format(iText.IO.LogMessageConstant.PROPERTY_IN_PERCENTS_NOT_SUPPORTED, Property
                                                          .MARGIN_TOP));
                }
                if (0 != spaceBefore.GetValue())
                {
                    attributes.Put(PdfName.SpaceBefore, new PdfNumber(spaceBefore.GetValue()));
                }
            }
            UnitValue spaceAfter = margins[marginsOrder[1]];

            if (spaceAfter != null)
            {
                if (!spaceAfter.IsPointValue())
                {
                    ILog logger = LogManager.GetLogger(typeof(AccessibleAttributesApplier));
                    logger.Error(MessageFormatUtil.Format(iText.IO.LogMessageConstant.PROPERTY_IN_PERCENTS_NOT_SUPPORTED, Property
                                                          .MARGIN_BOTTOM));
                }
                if (0 != spaceAfter.GetValue())
                {
                    attributes.Put(PdfName.SpaceAfter, new PdfNumber(spaceAfter.GetValue()));
                }
            }
            UnitValue startIndent = margins[marginsOrder[2]];

            if (startIndent != null)
            {
                if (!startIndent.IsPointValue())
                {
                    ILog logger = LogManager.GetLogger(typeof(AccessibleAttributesApplier));
                    logger.Error(MessageFormatUtil.Format(iText.IO.LogMessageConstant.PROPERTY_IN_PERCENTS_NOT_SUPPORTED, Property
                                                          .MARGIN_LEFT));
                }
                if (0 != startIndent.GetValue())
                {
                    attributes.Put(PdfName.StartIndent, new PdfNumber(startIndent.GetValue()));
                }
            }
            UnitValue endIndent = margins[marginsOrder[3]];

            if (endIndent != null)
            {
                if (!endIndent.IsPointValue())
                {
                    ILog logger = LogManager.GetLogger(typeof(AccessibleAttributesApplier));
                    logger.Error(MessageFormatUtil.Format(iText.IO.LogMessageConstant.PROPERTY_IN_PERCENTS_NOT_SUPPORTED, Property
                                                          .MARGIN_RIGHT));
                }
                if (0 != endIndent.GetValue())
                {
                    attributes.Put(PdfName.EndIndent, new PdfNumber(endIndent.GetValue()));
                }
            }
            float?firstLineIndent = renderer.GetPropertyAsFloat(Property.FIRST_LINE_INDENT);

            if (firstLineIndent != null && firstLineIndent != 0)
            {
                attributes.Put(PdfName.TextIndent, new PdfNumber((float)firstLineIndent));
            }
            TextAlignment?textAlignment = renderer.GetProperty <TextAlignment?>(Property.TEXT_ALIGNMENT);

            if (textAlignment != null && (!role.Equals(StandardRoles.TH) && !role.Equals(StandardRoles.TD)))
            {
                //for table cells there is an InlineAlign attribute (see below)
                attributes.Put(PdfName.TextAlign, TransformTextAlignmentValueToName(textAlignment));
            }
            // attributes are applied only on the first renderer
            if (renderer.isLastRendererForModelElement)
            {
                Rectangle bbox = renderer.GetOccupiedArea().GetBBox();
                attributes.Put(PdfName.BBox, new PdfArray(bbox));
            }
            if (role.Equals(StandardRoles.TH) || role.Equals(StandardRoles.TD) || role.Equals(StandardRoles.TABLE))
            {
                // For large tables the width can be changed from flush to flush so the Width attribute shouldn't be applied.
                // There are also technical issues with large tables widths being explicitly set as property on element during layouting
                // (even if user didn't explcitly specfied it). This is required due to specificity of large elements implementation,
                // however in this case we cannot distinguish layout-specific and user-specified width properties.
                if (!(renderer is TableRenderer) || ((Table)renderer.GetModelElement()).IsComplete())
                {
                    UnitValue width = renderer.GetProperty <UnitValue>(Property.WIDTH);
                    if (width != null && width.IsPointValue())
                    {
                        attributes.Put(PdfName.Width, new PdfNumber(width.GetValue()));
                    }
                }
                UnitValue height = renderer.GetProperty <UnitValue>(Property.HEIGHT);
                if (height != null && height.IsPointValue())
                {
                    attributes.Put(PdfName.Height, new PdfNumber(height.GetValue()));
                }
            }
            if (role.Equals(StandardRoles.TH) || role.Equals(StandardRoles.TD))
            {
                HorizontalAlignment?horizontalAlignment = renderer.GetProperty <HorizontalAlignment?>(Property.HORIZONTAL_ALIGNMENT
                                                                                                      );
                if (horizontalAlignment != null)
                {
                    attributes.Put(PdfName.BlockAlign, TransformBlockAlignToName(horizontalAlignment));
                }
                if (textAlignment != null && (textAlignment != TextAlignment.JUSTIFIED && textAlignment != TextAlignment.JUSTIFIED_ALL
                                              ))
                {
                    //there is no justified alignment for InlineAlign attribute
                    attributes.Put(PdfName.InlineAlign, TransformTextAlignmentValueToName(textAlignment));
                }
            }
        }
コード例 #3
0
 private static void ApplyBlockLevelLayoutAttributes(PdfName role, AbstractRenderer renderer, PdfDictionary
      attributes, PdfDocument doc) {
     float?[] margins = new float?[] { renderer.GetPropertyAsFloat(Property.MARGIN_TOP), renderer.GetPropertyAsFloat
         (Property.MARGIN_BOTTOM), renderer.GetPropertyAsFloat(Property.MARGIN_LEFT), renderer.GetPropertyAsFloat
         (Property.MARGIN_RIGHT) };
     int[] marginsOrder = new int[] { 0, 1, 2, 3 };
     //TODO set depending on writing direction
     float? spaceBefore = margins[marginsOrder[0]];
     if (spaceBefore != null && spaceBefore != 0) {
         attributes.Put(PdfName.SpaceBefore, new PdfNumber((float)spaceBefore));
     }
     float? spaceAfter = margins[marginsOrder[1]];
     if (spaceAfter != null && spaceAfter != 0) {
         attributes.Put(PdfName.SpaceAfter, new PdfNumber((float)spaceAfter));
     }
     float? startIndent = margins[marginsOrder[2]];
     if (startIndent != null && startIndent != 0) {
         attributes.Put(PdfName.StartIndent, new PdfNumber((float)startIndent));
     }
     float? endIndent = margins[marginsOrder[3]];
     if (endIndent != null && endIndent != 0) {
         attributes.Put(PdfName.EndIndent, new PdfNumber((float)endIndent));
     }
     float? firstLineIndent = renderer.GetProperty<float?>(Property.FIRST_LINE_INDENT);
     if (firstLineIndent != null && firstLineIndent != 0) {
         attributes.Put(PdfName.TextIndent, new PdfNumber((float)firstLineIndent));
     }
     TextAlignment? textAlignment = renderer.GetProperty<TextAlignment?>(Property.TEXT_ALIGNMENT);
     if (textAlignment != null && (!role.Equals(PdfName.TH) && !role.Equals(PdfName.TD))) {
         //for table cells there is an InlineAlign attribute (see below)
         attributes.Put(PdfName.TextAlign, TransformTextAlignmentValueToName(textAlignment));
     }
     bool connectedToTag = doc.GetTagStructureContext().IsElementConnectedToTag((IAccessibleElement)renderer.GetModelElement
         ());
     bool elementIsOnSinglePage = !connectedToTag && renderer.isLastRendererForModelElement;
     if (elementIsOnSinglePage) {
         Rectangle bbox = renderer.GetOccupiedArea().GetBBox();
         attributes.Put(PdfName.BBox, new PdfArray(bbox));
     }
     if (role.Equals(PdfName.TH) || role.Equals(PdfName.TD) || role.Equals(PdfName.Table)) {
         UnitValue width = renderer.GetProperty<UnitValue>(Property.WIDTH);
         if (width != null && width.IsPointValue()) {
             attributes.Put(PdfName.Width, new PdfNumber(width.GetValue()));
         }
         float? height = renderer.GetPropertyAsFloat(Property.HEIGHT);
         if (height != null) {
             attributes.Put(PdfName.Height, new PdfNumber((float)height));
         }
     }
     if (role.Equals(PdfName.TH) || role.Equals(PdfName.TD)) {
         HorizontalAlignment? horizontalAlignment = renderer.GetProperty<HorizontalAlignment?>(Property.HORIZONTAL_ALIGNMENT
             );
         if (horizontalAlignment != null) {
             attributes.Put(PdfName.BlockAlign, TransformBlockAlignToName(horizontalAlignment));
         }
         if (textAlignment != null && (textAlignment != TextAlignment.JUSTIFIED && textAlignment != TextAlignment.JUSTIFIED_ALL
             )) {
             //there is no justified alignment for InlineAlign attribute
             attributes.Put(PdfName.InlineAlign, TransformTextAlignmentValueToName(textAlignment));
         }
     }
 }