Skip to content

Commit

Permalink
reset table changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienSchminke committed Jun 15, 2023
1 parent efd300c commit 9247223
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 37 deletions.
30 changes: 0 additions & 30 deletions CONTRIBUTING.md

This file was deleted.

7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Contributors.md

This file was deleted.

2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,10 @@ pub extern crate log;
pub extern crate image as image_crate;
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
extern crate js_sys;

pub use lopdf;

//pub mod table;
pub mod color;
pub mod ctm;
pub mod date;
Expand Down
44 changes: 39 additions & 5 deletions src/pdf_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
use crate::glob_defines::OP_PATH_STATE_SET_LINE_WIDTH;
use crate::indices::{PdfLayerIndex, PdfPageIndex};
use crate::{
BlendMode, Color, CurTransMat, ExtendedGraphicsStateBuilder, Font, ImageXObject,
IndirectFontRef, Line, LineCapStyle, LineDashPattern, LineJoinStyle, Mm, PdfColor, PdfDocument,
Pt, TextMatrix, TextRenderingMode, XObject, XObjectRef,
};
use crate::{BlendMode, Color, CurTransMat, ExtendedGraphicsStateBuilder, Font, ImageXObject, IndirectFontRef, Line, LineCapStyle, LineDashPattern, LineJoinStyle, Mm, PdfColor, PdfDocument, Point, Pt, TextMatrix, TextRenderingMode, XObject, XObjectRef};
use lopdf::content::Operation;
use std::cell::RefCell;
use std::rc::Weak;
Expand Down Expand Up @@ -59,6 +55,43 @@ impl From<PdfLayer> for lopdf::Stream {
}

impl PdfLayerReference {
/* /// Add a table to the layer.
/// - [x] TODO add table based on given columns and rows
/// - [ ] TODO possibility to set column_lines manually
pub fn add_table(&self, column_count: u8, row_count: u8, bottom_left_corner: Point, width: Mm, height: Mm) {
let column_offset = width / column_count as f64;
let row_offset = height / row_count as f64;
let mut line_operations = Vec::new();
for col in 0..=column_count {
line_operations.append(&mut Line {
points: vec![(Point::new(Mm::from(bottom_left_corner.x) + column_offset * col as f64, Mm::from(bottom_left_corner.y) ), false),
(Point::new(Mm::from(bottom_left_corner.x) + column_offset * col as f64, Mm::from(bottom_left_corner.y) + height), false)],
is_closed: false,
has_fill: false,
has_stroke: true,
is_clipping_path: false,
}.into_stream_op());
}
for row in 0..=row_count {
line_operations.append(&mut Line {
points: vec![(Point::new(Mm::from(bottom_left_corner.x) , Mm::from(bottom_left_corner.y) + row_offset * row as f64), false),
(Point::new(Mm::from(bottom_left_corner.x) + width, Mm::from(bottom_left_corner.y) + row_offset * row as f64), false)],
is_closed: false,
has_fill: false,
has_stroke: true,
is_clipping_path: false,
}.into_stream_op());
}
for operation in line_operations {
self.add_operation(operation);
}
}
*/

/// Add a shape to the layer. Use `closed` to indicate whether the line is a closed line
/// Use has_fill to determine if the line should be filled.
pub fn add_shape(&self, line: Line) {
Expand Down Expand Up @@ -527,3 +560,4 @@ impl PdfLayerReference {
));
}
}

21 changes: 21 additions & 0 deletions src/table.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*extern crate grid;
use grid::Grid;
use crate::Mm;
/// Set the way of column line offset calculation
enum ColumnLineConfiguration<S: Into<String>> {
/// Calculates automatically the column offset so that each columns width is equal to each other.
/// The parameter is the amount of columns.
/// - [ ] in progress
Automatic(u8),
/// Set the columns offset manually.
/// The parameter is a List of the x-values started at the bottom left corner of the table
/// - [ ] in progress
Manually(Vec<Mm>),
/// Calculates automatically the column offset based on the text written in the table
/// The parameter contains a Grid with all text inputs in the table.
/// If you want to have empty cells at the beginning of the table generation.
/// Please use `Automatic` or `Manually` instead.
/// - [ ] in progress
ContentAdapting(Grid<S>),
}*/
14 changes: 14 additions & 0 deletions tests/add_table_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*use std::fs::File;
use std::io::BufWriter;
use printpdf::BuiltinFont;
use printpdf::{Mm, PdfDocument, Point};
#[test]
fn pdf_document_with_table() {
let (document, page_index, layer_index) = PdfDocument::new("Rechnung", Mm(210.0), Mm(297.0), "Ebene");
let font = document.add_builtin_font(BuiltinFont::TimesRoman).unwrap();
let current_layer = document.get_page(page_index).get_layer(layer_index);
current_layer.add_table(3, 10, Point::new(Mm(20.0), Mm(150.0)), Mm(100.0), Mm(100.0));
document.save(&mut BufWriter::new(File::create("test_table.pdf").unwrap())).unwrap();
}*/

0 comments on commit 9247223

Please sign in to comment.