Skip to content

Commit

Permalink
Improve image positioning a little
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiphoseer committed Sep 12, 2020
1 parent 3eb2bd9 commit 0c8d2fd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Added `--plain` option to the `dump` command to skip printing
tags that provide debugging information on lines and paragraphs.
- Minor improvements in image positioning and scaling.

### 11.09.2020

Expand Down
2 changes: 1 addition & 1 deletion src/cli/sdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ impl<'a> Document<'a> {
if let Some(pd) = self.print_driver {
let px = pd.scale_x(10 + site.pos_x);
let w = pd.scale_x(site._3);
let py = pd.scale_y(10 + site.pos_y);
let py = pd.scale_y(10 + site.pos_y - site._5 / 2);
let h = pd.scale_y(site._4 / 2);
let image = &self.images[site.img as usize];
page.draw_image(px, py, w, h, image, site.sel);
Expand Down
16 changes: 15 additions & 1 deletion src/print/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct VScaler<'a> {
last_vcount: usize,
iubpl: usize,
ibyte_index: usize,
skip_bits: u16,
ivpixel_rem: usize,
vpxl: bool,
}
Expand All @@ -42,6 +43,8 @@ impl<'a> VScaler<'a> {
let iubpl = image.bytes_per_line as usize;
let pixel_v_len = (h as usize) / (sel.h as usize);
let ivpixel_rem = 0;
let ibyte_index = (sel.y as usize) * iubpl + (sel.x as usize) / 8;
let skip_bits = sel.x % 8;
let vpxl = false;
Self {
sel_h: sel.h as usize,
Expand All @@ -54,7 +57,8 @@ impl<'a> VScaler<'a> {
vpixel_count: 0,
last_vcount: 0,
iubpl,
ibyte_index: (sel.y as usize) * iubpl + (sel.x as usize) / 8,
ibyte_index,
skip_bits,
ivpixel_rem,
vpxl,
}
Expand All @@ -66,6 +70,9 @@ impl<'a> VScaler<'a> {
let last_hcount = 0;
let hpxl = self.vpxl;
let ipixel_rem = 0;
for _ in 0..self.skip_bits {
let _ = ibit_iter.next();
}
let icurr = ibit_iter.next().unwrap_or(true);
HScaler {
vscaler: self,
Expand Down Expand Up @@ -93,6 +100,13 @@ impl<'a, 'b> HScaler<'a, 'b> {
fn next(&mut self) -> bool {
if self.vscaler.pixel_h_len == 0 {
while self.last_hcount < self.hpixel_count * self.vscaler.sel_w / self.vscaler.w {
if self.ipixel_rem == 7 {
self.hpxl = !self.hpxl;
//self.icurr = self.hpxl;
self.ipixel_rem = 0;
} else {
self.ipixel_rem += 1;
}
self.icurr = self.ibit_iter.next().unwrap();
self.last_hcount += 1;
}
Expand Down

0 comments on commit 0c8d2fd

Please sign in to comment.