当前位置: 首页>>代码示例>>C#>>正文


C# PdfLine.GetChunk方法代码示例

本文整理汇总了C#中iTextSharp.text.pdf.PdfLine.GetChunk方法的典型用法代码示例。如果您正苦于以下问题:C# PdfLine.GetChunk方法的具体用法?C# PdfLine.GetChunk怎么用?C# PdfLine.GetChunk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在iTextSharp.text.pdf.PdfLine的用法示例。


在下文中一共展示了PdfLine.GetChunk方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PdfCell


//.........这里部分代码省略.........
                                }
                                line.ResetAlignment();
                                AddLine(line);
                                line = new PdfLine(left + item.IndentationLeft, right, alignment, leading);
                            }
                        }
                        line = new PdfLine(left, right, alignment, leading);
                        break;
                        // if the element is something else
                    default:
                        allActions = new ArrayList();
                        ProcessActions(ele, null, allActions);
                        aCounter = 0;

                        float currentLineLeading = leading;
                        float currentLeft = left;
                        float currentRight = right;
                        if (ele is Phrase) {
                            currentLineLeading = ((Phrase) ele).Leading;
                        }
                        if (ele is Paragraph) {
                            Paragraph p = (Paragraph) ele;
                            currentLeft += p.IndentationLeft;
                            currentRight -= p.IndentationRight;
                        }
                        if (line == null) {
                            line = new PdfLine(currentLeft, currentRight, alignment, currentLineLeading);
                        }
                        // we loop over the chunks
                        ArrayList chunks = ele.Chunks;
                        if (chunks.Count == 0) {
                            AddLine(line); // add empty line - all cells need some lines even if they are empty
                            line = new PdfLine(currentLeft, currentRight, alignment, currentLineLeading);
                        }
                        else {
                            foreach (Chunk c in chunks) {
                                chunk = new PdfChunk(c, (PdfAction)allActions[aCounter++]);
                                while ((overflow = line.Add(chunk)) != null) {
                                    AddLine(line);
                                    line = new PdfLine(currentLeft, currentRight, alignment, currentLineLeading);
                                    chunk = overflow;
                                }
                            }
                        }
                        // if the element is a paragraph, section or chapter, we reset the alignment and add the line
                        switch (ele.Type) {
                            case Element.PARAGRAPH:
                            case Element.SECTION:
                            case Element.CHAPTER:
                                line.ResetAlignment();
                                FlushCurrentLine();
                                break;
                        }
                        break;
                }
            }
            FlushCurrentLine();
            if (lines.Count > cell.MaxLines) {
                while (lines.Count > cell.MaxLines) {
                    RemoveLine(lines.Count - 1);
                }
                if (cell.MaxLines > 0) {
                    String more = cell.ShowTruncation;
                    if (more != null && more.Length > 0) {
                        // Denote that the content has been truncated
                        lastLine = (PdfLine) lines[lines.Count - 1];
                        if (lastLine.Size >= 0) {
                            PdfChunk lastChunk = lastLine.GetChunk(lastLine.Size - 1);
                            float moreWidth = new PdfChunk(more, lastChunk).Width;
                            while (lastChunk.ToString().Length > 0 && lastChunk.Width + moreWidth > right - left) {
                                // Remove characters to leave room for the 'more' indicator
                                lastChunk.Value = lastChunk.ToString().Substring(0, lastChunk.Length - 1);
                            }
                            lastChunk.Value = lastChunk.ToString() + more;
                        } else {
                            lastLine.Add(new PdfChunk(new Chunk(more), null));
                        }
                    }
                }
            }
            // we set some additional parameters
            if (useDescender && lastLine != null) {
                contentHeight -= lastLine.Descender;
            }

            // adjust first line height so that it touches the top
            if (lines.Count > 0) {
                firstLine = (PdfLine) lines[0];
                float firstLineRealHeight = FirstLineRealHeight;
                contentHeight -= firstLine.Height;
                firstLine.height = firstLineRealHeight;
                contentHeight += firstLineRealHeight;
            }

            float newBottom = top - contentHeight - (2f * Cellpadding) - (2f * Cellspacing);
            newBottom -= GetBorderWidthInside(TOP_BORDER) + GetBorderWidthInside(BOTTOM_BORDER);
            Bottom = newBottom;

            this.rownumber = rownumber;
        }
开发者ID:hjgode,项目名称:iTextSharpCF,代码行数:101,代码来源:PdfCell.cs

示例2: WriteLineToContent

        /**
        * Writes a text line to the document. It takes care of all the attributes.
        * <P>
        * Before entering the line position must have been established and the
        * <CODE>text</CODE> argument must be in text object scope (<CODE>beginText()</CODE>).
        * @param line the line to be written
        * @param text the <CODE>PdfContentByte</CODE> where the text will be written to
        * @param graphics the <CODE>PdfContentByte</CODE> where the graphics will be written to
        * @param currentValues the current font and extra spacing values
        * @param ratio
        * @throws DocumentException on error
        */
        internal float WriteLineToContent(PdfLine line, PdfContentByte text, PdfContentByte graphics, Object[] currentValues, float ratio)  {
            PdfFont currentFont = (PdfFont)(currentValues[0]);
            float lastBaseFactor = (float)currentValues[1];
            //PdfChunk chunkz;
            int numberOfSpaces;
            int lineLen;
            bool isJustified;
            float hangingCorrection = 0;
            float hScale = 1;
            float lastHScale = float.NaN;
            float baseWordSpacing = 0;
            float baseCharacterSpacing = 0;
            float glueWidth = 0;
            float lastX = text.XTLM + line.OriginalWidth;
            
            numberOfSpaces = line.NumberOfSpaces;
            lineLen = line.GetLineLengthUtf32();
            // does the line need to be justified?
            isJustified = line.HasToBeJustified() && (numberOfSpaces != 0 || lineLen > 1);
            int separatorCount = line.GetSeparatorCount();
            if (separatorCount > 0) {
                glueWidth = line.WidthLeft / separatorCount;
            }
            else if (isJustified && separatorCount == 0) {
                if (line.NewlineSplit && line.WidthLeft >= (lastBaseFactor * (ratio * numberOfSpaces + lineLen - 1))) {
                    if (line.RTL) {
                        text.MoveText(line.WidthLeft - lastBaseFactor * (ratio * numberOfSpaces + lineLen - 1), 0);
                    }
                    baseWordSpacing = ratio * lastBaseFactor;
                    baseCharacterSpacing = lastBaseFactor;
                }
                else {
                    float width = line.WidthLeft;
                    PdfChunk last = line.GetChunk(line.Size - 1);
                    if (last != null) {
                        String s = last.ToString();
                        char c;
                        if (s.Length > 0 && hangingPunctuation.IndexOf((c = s[s.Length - 1])) >= 0) {
                            float oldWidth = width;
                            width += last.Font.Width(c) * 0.4f;
                            hangingCorrection = width - oldWidth;
                        }
                    }
                    float baseFactor = width / (ratio * numberOfSpaces + lineLen - 1);
                    baseWordSpacing = ratio * baseFactor;
                    baseCharacterSpacing = baseFactor;
                    lastBaseFactor = baseFactor;
                }
            }
            else if (line.alignment == Element.ALIGN_LEFT || line.alignment == Element.ALIGN_UNDEFINED) {
                lastX -= line.WidthLeft;
            }
            
            int lastChunkStroke = line.LastStrokeChunk;
            int chunkStrokeIdx = 0;
            float xMarker = text.XTLM;
            float baseXMarker = xMarker;
            float yMarker = text.YTLM;
            bool adjustMatrix = false;
            float tabPosition = 0;
            
            // looping over all the chunks in 1 line
            foreach (PdfChunk chunk in line) {
                if (IsTagged(writer) && chunk.accessibleElement != null) {
                    text.OpenMCBlock(chunk.accessibleElement);
                }
                BaseColor color = chunk.Color;
                float fontSize = chunk.Font.Size;
                float ascender;
                float descender;
                if (chunk.IsImage())
                {
                    ascender = chunk.Height();
                    descender = 0;
                }
                else
                {
                    ascender = chunk.Font.Font.GetFontDescriptor(BaseFont.ASCENT, fontSize);
                    descender = chunk.Font.Font.GetFontDescriptor(BaseFont.DESCENT, fontSize);
                }
                hScale = 1;
                
                if (chunkStrokeIdx <= lastChunkStroke) {
                    float width;
                    if (isJustified) {
                        width = chunk.GetWidthCorrected(baseCharacterSpacing, baseWordSpacing);
                    }
                    else {
//.........这里部分代码省略.........
开发者ID:NelsonSantos,项目名称:fyiReporting-Android,代码行数:101,代码来源:PdfDocument.cs

示例3: WriteLineToContent

        /**
        * Writes a text line to the document. It takes care of all the attributes.
        * <P>
        * Before entering the line position must have been established and the
        * <CODE>text</CODE> argument must be in text object scope (<CODE>beginText()</CODE>).
        * @param line the line to be written
        * @param text the <CODE>PdfContentByte</CODE> where the text will be written to
        * @param graphics the <CODE>PdfContentByte</CODE> where the graphics will be written to
        * @param currentValues the current font and extra spacing values
        * @param ratio
        * @throws DocumentException on error
        */
        internal void WriteLineToContent(PdfLine line, PdfContentByte text, PdfContentByte graphics, Object[] currentValues, float ratio)
        {
            PdfFont currentFont = (PdfFont)(currentValues[0]);
            float lastBaseFactor = (float)currentValues[1];
            //PdfChunk chunkz;
            int numberOfSpaces;
            int lineLen;
            bool isJustified;
            float hangingCorrection = 0;
            float hScale = 1;
            float lastHScale = float.NaN;
            float baseWordSpacing = 0;
            float baseCharacterSpacing = 0;

            numberOfSpaces = line.NumberOfSpaces;
            lineLen = line.ToString().Length;
            // does the line need to be justified?
            isJustified = line.HasToBeJustified() && (numberOfSpaces != 0 || lineLen > 1);
            if (isJustified) {
                if (line.NewlineSplit && line.WidthLeft >= (lastBaseFactor * (ratio * numberOfSpaces + lineLen - 1))) {
                    if (line.RTL) {
                        text.MoveText(line.WidthLeft - lastBaseFactor * (ratio * numberOfSpaces + lineLen - 1), 0);
                    }
                    baseWordSpacing = ratio * lastBaseFactor;
                    baseCharacterSpacing = lastBaseFactor;
                }
                else {
                    float width = line.WidthLeft;
                    PdfChunk last = line.GetChunk(line.Size - 1);
                    if (last != null) {
                        String s = last.ToString();
                        char c;
                        if (s.Length > 0 && hangingPunctuation.IndexOf((c = s[s.Length - 1])) >= 0) {
                            float oldWidth = width;
                            width += last.Font.Width(c) * 0.4f;
                            hangingCorrection = width - oldWidth;
                        }
                    }
                    float baseFactor = width / (ratio * numberOfSpaces + lineLen - 1);
                    baseWordSpacing = ratio * baseFactor;
                    baseCharacterSpacing = baseFactor;
                    lastBaseFactor = baseFactor;
                }
            }

            int lastChunkStroke = line.LastStrokeChunk;
            int chunkStrokeIdx = 0;
            float xMarker = text.XTLM;
            float baseXMarker = xMarker;
            float yMarker = text.YTLM;
            bool adjustMatrix = false;

            // looping over all the chunks in 1 line
            foreach (PdfChunk chunk in line) {
                Color color = chunk.Color;
                hScale = 1;

                if (chunkStrokeIdx <= lastChunkStroke) {
                    float width;
                    if (isJustified) {
                        width = chunk.GetWidthCorrected(baseCharacterSpacing, baseWordSpacing);
                    }
                    else
                        width = chunk.Width;
                    if (chunk.IsStroked()) {
                        PdfChunk nextChunk = line.GetChunk(chunkStrokeIdx + 1);
                        if (chunk.IsAttribute(Chunk.BACKGROUND)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.BACKGROUND))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            float fontSize = chunk.Font.Size;
                            float ascender = chunk.Font.Font.GetFontDescriptor(BaseFont.ASCENT, fontSize);
                            float descender = chunk.Font.Font.GetFontDescriptor(BaseFont.DESCENT, fontSize);
                            Object[] bgr = (Object[])chunk.GetAttribute(Chunk.BACKGROUND);
                            graphics.SetColorFill((Color)bgr[0]);
                            float[] extra = (float[])bgr[1];
                            graphics.Rectangle(xMarker - extra[0],
                                yMarker + descender - extra[1] + chunk.TextRise,
                                width - subtract + extra[0] + extra[2],
                                ascender - descender + extra[1] + extra[3]);
                            graphics.Fill();
                            graphics.SetGrayFill(0);
                        }
                        if (chunk.IsAttribute(Chunk.UNDERLINE)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.UNDERLINE))
//.........这里部分代码省略.........
开发者ID:hjgode,项目名称:iTextSharpCF,代码行数:101,代码来源:PdfDocument.cs


注:本文中的iTextSharp.text.pdf.PdfLine.GetChunk方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。