Esempio n. 1
0
        private void RenderPhotoRow(PhotoRowLayout layout, ITableRow row)
        {
            //	In the design we represent a photo row as a pair of table rows
            //	without a table: one row for the photos, and the other for the
            //	captions. This design is useful for PDF, and requires special
            //	handling of borders to make the vertical pairs of cells (photo
            //	cell and caption cell) appear as a single cell. But it's not
            //	necessary in Word because we can just add the photo and caption
            //	as two paragraphs in a single cell. So deconstruct the photo
            //	row into its pairs of cells and then render each pair as a
            //	single cell.
            for (int x = 0; x < layout.NumPhotos; ++x)
            {
                PhotoLayout photoCell   = (PhotoLayout)layout.PhotoRow.GetSubLayoutAtIndex(x).GetSubLayoutAtIndex(0);
                TextLayout  captionCell = (TextLayout)layout.CaptionRow.GetSubLayoutAtIndex(x).GetSubLayoutAtIndex(0);

                s.TableCellStyle cellStyle = null;
                if (layout.Style != null)
                {
                    s.PhotoStyle photoStyle = (s.PhotoStyle)layout.Style;
                    cellStyle = new s.TableCellStyle
                    {
                        Padding = photoStyle.Padding
                    };
                }
                ITableCell cell = row.AddCell(1, cellStyle, layout.TrackingInfo);
                RenderPhoto(photoCell, cell);
                RenderText(captionCell, cell);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Copy constructor used during page break handling.
 /// </summary>
 public PhotoRowLayout(PhotoRowLayout src)
     : base(src)
 {
     _numCells  = src._numCells;
     _numPhotos = src._numPhotos;
     _cellWidth = src._cellWidth;
 }
Esempio n. 3
0
        public override Layout DoPageBreak()
        {
            using (new TraceContextPusher(_generator, _traceContext))
            {
                //	We never split a photo row, so on a page break we always move all
                //	of our content into a copy of ourself, and return that copy. This
                //	leaves ourself empty, and the base class implementation will then
                //	remove us from our container.
                PhotoRowLayout copy = new PhotoRowLayout(this);

                copy._photoRow   = this._photoRow;
                copy._captionRow = this._captionRow;
                this.RemoveSubLayout(_photoRow);
                this.RemoveSubLayout(_captionRow);
                copy.AddSubLayout(_photoRow);
                copy.AddSubLayout(_captionRow);

                //	Empty ourself
                _subLayouts.Clear();
                _photoRow   = null;
                _captionRow = null;

                return(copy);
            }
        }
Esempio n. 4
0
        private void RenderPhotoRowLayout(PhotoRowLayout layout, Page page)
        {
            for (int x = 0; x < layout.NumPhotos; ++x)
            {
                //	There's always a photo...
                PhotoLayout photoCell = (PhotoLayout)layout.PhotoRow.GetSubLayoutAtIndex(x).GetSubLayoutAtIndex(0);
                RenderPhotoLayout(photoCell, page);

                //	but not always a caption
                TableCellLayout captionCell = (TableCellLayout)layout.CaptionRow.GetSubLayoutAtIndex(x);
                if (captionCell.NumSubLayouts > 0)
                {
                    TextLayout caption = (TextLayout)captionCell.GetSubLayoutAtIndex(0);
                    RenderTextLayout(caption, page);
                }
            }
        }
Esempio n. 5
0
        public override Position Draft(Rectangle bounds)
        {
            if (!_staticConditionsSatisfied)
            {
                return(bounds.BottomLeft);
            }

            using (new TraceContextPusher(_generator, _traceContext))
            {
                Trace("start bounds={0}", bounds);

                //	A photo table is implemented like this: Create one or more photo
                //	row layouts and add them all as normal sequential sublayouts of
                //	the table. Assign photos to the rows, where the number of photos
                //	in each row is defined by the table's _columns property. The last
                //	row will have fewer photos if the number of photos is not an even
                //	multiple of the number of columns.
                //
                //	A photo row is implemented as a normal table with two normal
                //	rows, one for the photos and the other for the captions. A photo
                //	row cannot be split across a page break, but the photo table
                //	can be split in the normal way by moving some photo rows onto
                //	the next page.

                //	If we have no photo content then don't draw ourself at all. We know
                //	that _columns is greater than zero because we checked it during load.
                if (_photos.Count == 0)
                {
                    return(bounds.BottomLeft);
                }

                //	Work out the column width. All photo cells will have the same width.
                //	We don't apply padding to the table or to the row, because the table
                //	is just structural and isn't part of the designed layout. When we
                //	get down to the photo layout we'll apply padding there.
                _columnWidth = bounds.Width / _columns;

                //	Work out the photo size from the column width
                if (_columnWidth < _maxPhotoSize.Width)
                {
                    double scale        = (double)_columnWidth / (double)_maxPhotoSize.Width;
                    int    scaledWidth  = (int)(_maxPhotoSize.Width * scale);
                    int    scaledHeight = (int)(_maxPhotoSize.Height * scale);
                    _maxPhotoSize = new Size(scaledWidth, scaledHeight);
                }

                for (int photoIndex = 0; photoIndex < _photos.Count;)                 // will be incremented inside the inner loop
                {
                    PhotoRowLayout row = new PhotoRowLayout(
                        _columns, _generator, _trackingInfo.LineNumber, _trackingInfo.LinePosition);
                    AddSubLayout(row);
                    while (row.NumPhotos < _columns)
                    {
                        if (photoIndex >= _photos.Count)
                        {
                            break;
                        }

                        CompositePhotoLayout photo = _photos[photoIndex++];
                        row.AddPhoto(photo.PhotoLayout, photo.CaptionLayout);
                    }
                }

                //	Pass the column width on to the rows
                foreach (PhotoRowLayout row in _subLayouts)
                {
                    row.SetColumnWidth(_columnWidth);
                }

                Trace("end _bounds={0}", _bounds);
                return(base.Draft(bounds));
            }
        }