Пример #1
0
 private void writeBorder(MemoryStream os, byte[] borderType)
 {
     // horizontal and vertical, top, left, bottom, right
     os.WriteByte(RtfWriter.escape);
     os.Write(borderType, 0, borderType.Length);
     // line style
     os.WriteByte(RtfWriter.escape);
     os.Write(RtfRow.tableBorder, 0, RtfRow.tableBorder.Length);
     // borderwidth
     os.WriteByte(RtfWriter.escape);
     os.Write(RtfRow.tableBorderWidth, 0, RtfRow.tableBorderWidth.Length);
     writeInt(os, (int)(borderWidth * RtfWriter.twipsFactor));
     // border color
     os.WriteByte(RtfWriter.escape);
     os.Write(RtfRow.tableBorderColor, 0, RtfRow.tableBorderColor.Length);
     if (borderColor == null)
     {
         writeInt(os, writer.addColor(new Color(0, 0, 0)));
     }
     else
     {
         writeInt(os, writer.addColor(borderColor));
     }
     os.WriteByte((byte)'\n');
 }
Пример #2
0
        /// <summary>
        /// Write the properties of the RtfCell.
        /// </summary>
        /// <param name="os">
        /// The Stream to which to write the properties of the RtfCell to.
        /// </param>
        /// <returns></returns>
        public bool writeCellSettings(MemoryStream os)
        {
            try {
                float  lWidth, tWidth, rWidth, bWidth;
                byte[] lStyle, tStyle, rStyle, bStyle;

                if (store is RtfTableCell)
                {
                    RtfTableCell c = (RtfTableCell)store;
                    lWidth = c.LeftBorderWidth;
                    tWidth = c.TopBorderWidth;
                    rWidth = c.RightBorderWidth;
                    bWidth = c.BottomBorderWidth;
                    lStyle = RtfTableCell.getStyleControlWord(c.LeftBorderStyle);
                    tStyle = RtfTableCell.getStyleControlWord(c.TopBorderStyle);
                    rStyle = RtfTableCell.getStyleControlWord(c.RightBorderStyle);
                    bStyle = RtfTableCell.getStyleControlWord(c.BottomBorderStyle);
                }
                else
                {
                    lWidth = tWidth = rWidth = bWidth = store.BorderWidth;
                    lStyle = tStyle = rStyle = bStyle = RtfRow.tableBorder;
                }

                // <!-- steffen
                if (mergeType == MERGE_HORIZ_PREV || mergeType == MERGE_BOTH_PREV)
                {
                    return(true);
                }
                switch (mergeType)
                {
                case MERGE_VERT_FIRST:
                    os.WriteByte(RtfWriter.escape);
                    os.Write(cellVMergeFirst, 0, cellVMergeFirst.Length);
                    break;

                case MERGE_BOTH_FIRST:
                    os.WriteByte(RtfWriter.escape);
                    os.Write(cellVMergeFirst, 0, cellVMergeFirst.Length);
                    break;

                case MERGE_HORIZ_PREV:
                    os.WriteByte(RtfWriter.escape);
                    os.Write(cellMergePrev, 0, cellMergePrev.Length);
                    break;

                case MERGE_VERT_PREV:
                    os.WriteByte(RtfWriter.escape);
                    os.Write(cellVMergePrev, 0, cellVMergePrev.Length);
                    break;

                case MERGE_BOTH_PREV:
                    os.WriteByte(RtfWriter.escape);
                    os.Write(cellMergeFirst, 0, cellMergeFirst.Length);
                    break;
                }
                // -->
                switch (store.VerticalAlignment)
                {
                case Element.ALIGN_BOTTOM:
                    os.WriteByte(RtfWriter.escape);
                    os.Write(cellVerticalAlignBottom, 0, cellVerticalAlignBottom.Length);
                    break;

                case Element.ALIGN_CENTER:
                    os.WriteByte(RtfWriter.escape);
                    os.Write(cellVerticalAlignCenter, 0, cellVerticalAlignCenter.Length);
                    break;

                case Element.ALIGN_TOP:
                    os.WriteByte(RtfWriter.escape);
                    os.Write(cellVerticalAlignTop, 0, cellVerticalAlignTop.Length);
                    break;
                }

                if (((store.Border & Rectangle.LEFT) == Rectangle.LEFT) &&
                    (lWidth > 0))
                {
                    os.WriteByte(RtfWriter.escape);
                    os.Write(cellBorderLeft, 0, cellBorderLeft.Length);
                    os.WriteByte(RtfWriter.escape);
                    os.Write(lStyle, 0, lStyle.Length);
                    os.WriteByte(RtfWriter.escape);
                    os.Write(RtfRow.tableBorderWidth, 0, RtfRow.tableBorderWidth.Length);
                    writeInt(os, (int)(lWidth * RtfWriter.twipsFactor));
                    os.WriteByte(RtfWriter.escape);
                    os.Write(RtfRow.tableBorderColor, 0, RtfRow.tableBorderColor.Length);
                    if (store.BorderColor == null)
                    {
                        writeInt(os, writer.addColor(new
                                                     Color(0, 0, 0)));
                    }
                    else
                    {
                        writeInt(os, writer.addColor(store.BorderColor));
                    }
                    os.WriteByte((byte)'\n');
                }
                if (((store.Border & Rectangle.TOP) == Rectangle.TOP) && (tWidth > 0))
                {
                    os.WriteByte(RtfWriter.escape);
                    os.Write(cellBorderTop, 0, cellBorderTop.Length);
                    os.WriteByte(RtfWriter.escape);
                    os.Write(tStyle, 0, tStyle.Length);
                    os.WriteByte(RtfWriter.escape);
                    os.Write(RtfRow.tableBorderWidth, 0, RtfRow.tableBorderWidth.Length);
                    writeInt(os, (int)(tWidth * RtfWriter.twipsFactor));
                    os.WriteByte(RtfWriter.escape);
                    os.Write(RtfRow.tableBorderColor, 0, RtfRow.tableBorderColor.Length);
                    if (store.BorderColor == null)
                    {
                        writeInt(os, writer.addColor(new
                                                     Color(0, 0, 0)));
                    }
                    else
                    {
                        writeInt(os, writer.addColor(store.BorderColor));
                    }
                    os.WriteByte((byte)'\n');
                }
                if (((store.Border & Rectangle.BOTTOM) == Rectangle.BOTTOM) &&
                    (bWidth > 0))
                {
                    os.WriteByte(RtfWriter.escape);
                    os.Write(cellBorderBottom, 0, cellBorderBottom.Length);
                    os.WriteByte(RtfWriter.escape);
                    os.Write(bStyle, 0, bStyle.Length);
                    os.WriteByte(RtfWriter.escape);
                    os.Write(RtfRow.tableBorderWidth, 0, RtfRow.tableBorderWidth.Length);
                    writeInt(os, (int)(bWidth * RtfWriter.twipsFactor));
                    os.WriteByte(RtfWriter.escape);
                    os.Write(RtfRow.tableBorderColor, 0, RtfRow.tableBorderColor.Length);
                    if (store.BorderColor == null)
                    {
                        writeInt(os, writer.addColor(new
                                                     Color(0, 0, 0)));
                    }
                    else
                    {
                        writeInt(os, writer.addColor(store.BorderColor));
                    }
                    os.WriteByte((byte)'\n');
                }
                if (((store.Border & Rectangle.RIGHT) == Rectangle.RIGHT) &&
                    (rWidth > 0))
                {
                    os.WriteByte(RtfWriter.escape);
                    os.Write(cellBorderRight, 0, cellBorderRight.Length);
                    os.WriteByte(RtfWriter.escape);
                    os.Write(rStyle, 0, rStyle.Length);
                    os.WriteByte(RtfWriter.escape);
                    os.Write(RtfRow.tableBorderWidth, 0, RtfRow.tableBorderWidth.Length);
                    writeInt(os, (int)(rWidth * RtfWriter.twipsFactor));
                    os.WriteByte(RtfWriter.escape);
                    os.Write(RtfRow.tableBorderColor, 0, RtfRow.tableBorderColor.Length);
                    if (store.BorderColor == null)
                    {
                        writeInt(os, writer.addColor(new
                                                     Color(0, 0, 0)));
                    }
                    else
                    {
                        writeInt(os, writer.addColor(store.BorderColor));
                    }
                    os.WriteByte((byte)'\n');
                }
                os.WriteByte(RtfWriter.escape);
                os.Write(cellBackgroundColor, 0, cellBackgroundColor.Length);
                if (store.BackgroundColor == null)
                {
                    writeInt(os, writer.addColor(new
                                                 Color(255, 255, 255)));
                }
                else
                {
                    writeInt(os,
                             writer.addColor(store.BackgroundColor));
                }
                os.WriteByte((byte)'\n');
                os.WriteByte(RtfWriter.escape);
                os.Write(cellWidthStyle, 0, cellWidthStyle.Length);
                os.WriteByte((byte)'\n');
                os.WriteByte(RtfWriter.escape);
                os.Write(cellWidthTag, 0, cellWidthTag.Length);
                writeInt(os, cellWidth);
                os.WriteByte((byte)'\n');
                if (cellpadding > 0)
                {
                    // values
                    os.WriteByte(RtfWriter.escape);
                    os.Write(cellPaddingLeft, 0, cellPaddingLeft.Length);
                    writeInt(os, cellpadding / 2);
                    os.WriteByte(RtfWriter.escape);
                    os.Write(cellPaddingTop, 0, cellPaddingTop.Length);
                    writeInt(os, cellpadding / 2);
                    os.WriteByte(RtfWriter.escape);
                    os.Write(cellPaddingRight, 0, cellPaddingRight.Length);
                    writeInt(os, cellpadding / 2);
                    os.WriteByte(RtfWriter.escape);
                    os.Write(cellPaddingBottom, 0, cellPaddingBottom.Length);
                    writeInt(os, cellpadding / 2);
                    // unit
                    os.WriteByte(RtfWriter.escape);
                    os.Write(cellPaddingLeftUnit, 0, cellPaddingLeftUnit.Length);
                    os.WriteByte(RtfWriter.escape);
                    os.Write(cellPaddingTopUnit, 0, cellPaddingTopUnit.Length);
                    os.WriteByte(RtfWriter.escape);
                    os.Write(cellPaddingRightUnit, 0, cellPaddingRightUnit.Length);
                    os.WriteByte(RtfWriter.escape);
                    os.Write(cellPaddingBottomUnit, 0, cellPaddingBottomUnit.Length);
                }
                os.WriteByte(RtfWriter.escape);
                os.Write(cellRightBorder, 0, cellRightBorder.Length);
                writeInt(os, cellRight);
            }
            catch (IOException e) {
                return(false);
            }
            return(true);
        }