Skip to content

Commit

Permalink
Fixed build errors from rusttype merge
Browse files Browse the repository at this point in the history
  • Loading branch information
fschutt committed Feb 12, 2018
1 parent e509f3e commit 9e037e3
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 94 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "printpdf"
version = "0.2.2"
version = "0.2.3"
authors = ["Felix Schütt <[email protected]>"]
repository = "https://github.com/fschutt/printpdf"
homepage = "https://github.com/fschutt/printpdf"
Expand All @@ -10,7 +10,7 @@ description = "Rust library for writing PDF files"

[dependencies]
lopdf = "0.15.1"
rusttype = { git = "https://github.com/redox-os/rusttype", rev = "753ea0df5d537a73b3a94e6c5ff406e204b4431e" }
rusttype = "0.3.1"
error-chain = "0.11.0"
chrono = "0.4.0"
rand = { version = "0.4.2", default-features = false }
Expand Down
37 changes: 0 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,6 @@ Currently, printpdf can only write documents, not read them.

## Getting started

### Installation requirements

#### Linux

You need to install freetype, if you haven't already installed it:
```rust
sudo apt install libfreetype6-dev
```

#### Windows

##### pc-windows-gnu

In order to easily setup freetype just get MSYS2 and install either the `mingw-w64-x86_64-freetype` or `mingw-w64-i686-freetype` package and then use Rust from within the correct mingw shell of MSYS2.

More information on setting up MSYS2 for Rust can be found in [the Rust readme](https://github.com/rust-lang/rust#building-on-windows)

##### pc-windows-msvc

Prebuilt libraries for freetype are available [here](https://github.com/PistonDevelopers/binaries).

Then in the root of your project, in one of the parent directories, or in your home directory, create a .cargo directory. This directory should contain a `config` file that contains the following snippet:

```toml
[target.i686-pc-windows-msvc.freetype]
rustc-link-search = ["C:\\Path\\To\\binaries\\i686"]
rustc-link-lib = ["freetype"]

[target.x86_64-pc-windows-msvc.freetype]
rustc-link-search = ["C:\\Path\\To\\binaries\\x86_64"]
rustc-link-lib = ["freetype"]
```

For more informations, check [the official Cargo documentation](http://doc.crates.io/build-script.html#overriding-build-scripts).

(taken from [this README](https://github.com/PistonDevelopers/freetype-sys/blob/master/README.md))

### Writing PDF

#### Simple page
Expand Down
2 changes: 0 additions & 2 deletions src/errors/errors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![allow(unused_qualifications)]

extern crate rusttype;

use super::*;

error_chain! {
Expand Down
37 changes: 0 additions & 37 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,6 @@
//! - PDF layers (you should be able to open the PDF in Illustrator and have the layers appear)
//!
//! # Getting started
//!
//! ## Installation requirements
//!
//! ### Linux
//!
//! You need to install freetype, if you haven't already installed it:
//! ```
//! sudo apt install libfreetype6-dev
//! ```
//!
//! ### Windows
//!
//! #### pc-windows-gnu
//!
//! In order to easily setup freetype just get MSYS2 and install either the `mingw-w64-x86_64-freetype` or `mingw-w64-i686-freetype` package and then use Rust from within the correct mingw shell of MSYS2.
//!
//! More information on setting up MSYS2 for Rust can be found in [the Rust readme](https://github.com/rust-lang/rust#building-on-windows)
//!
//! #### pc-windows-msvc
//!
//! Prebuilt libraries for freetype are available [here](https://github.com/PistonDevelopers/binaries).
//!
//! Then in the root of your project, in one of the parent directories, or in your home directory, create a .cargo directory. This directory should contain a `config` file that contains the following snippet:
//!
//! ```toml
//! [target.i686-pc-windows-msvc.freetype]
//! rustc-link-search = ["C:\\Path\\To\\binaries\\i686"]
//! rustc-link-lib = ["freetype"]
//!
//! [target.x86_64-pc-windows-msvc.freetype]
//! rustc-link-search = ["C:\\Path\\To\\binaries\\x86_64"]
//! rustc-link-lib = ["freetype"]
//! ```
//!
//! For more informations, check [the official Cargo documentation](http://doc.crates.io/build-script.html#overriding-build-scripts).
//!
//! (taken from [this README](https://github.com/PistonDevelopers/freetype-sys/blob/master/README.md))
//!
//! ## Writing PDF
//!
Expand Down
1 change: 0 additions & 1 deletion src/types/pdf_layer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! PDF layer management. Layers can contain referenced or real content.
use lopdf;
use rusttype;

use indices::{PdfPageIndex, PdfLayerIndex};
use std::rc::Weak;
Expand Down
34 changes: 19 additions & 15 deletions src/types/plugins/graphics/two_dimensional/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

//! Embedding fonts in 2D for Pdf
use lopdf;
use rusttype;

use lopdf::{Stream as LoStream, Dictionary as LoDictionary};
use lopdf::StringFormat;
use std::collections::{HashMap, BTreeMap};
Expand Down Expand Up @@ -142,6 +140,8 @@ impl ExternalFont {
pub fn new<R>(mut font_stream: R, font_index: usize)
-> Result<Self, PrintpdfError> where R: ::std::io::Read
{
use errors::FontError;

// read font from stream and parse font metrics
let mut buf = Vec::<u8>::new();
font_stream.read_to_end(&mut buf)?;
Expand All @@ -152,7 +152,7 @@ impl ExternalFont {

if let None = font {
if let None = collection.into_fonts().nth(0) {
return Err(Error::from_kind(FontError));
return Err(PrintpdfError::from_kind(FontError));
}
}

Expand Down Expand Up @@ -220,28 +220,35 @@ impl ExternalFont {
// Widths (or heights, depends on self.vertical_writing)
// of the individual characters, indexed by glyph id
let mut widths = HashMap::<u32, u32>::new();
// Height of the space (0x0020 character), to scale the font correctly
let mut space_height;

// Glyph IDs - (Unicode IDs - character width, character height)
let mut cmap = BTreeMap::<u32, (u32, u32, u32)>::new();
cmap.insert(0, (0, 1000, 1000));

for unicode in 0x0000..0xffff {

let glyph = font.glyph(Cpg(Cp(unicode)));

if let Some(glyph) = glyph {
if glyph.id().0 == 0 { continue; }

if glyph.id().0 == 0 {
continue;
}

let glyph_id = glyph.id().0;

if let Some(glyph) = font.glyph(Cgid(Gid(glyph_id))) {

if let Some(glyph_metrics) = glyph.standalone().get_data() {

if let Some(extents) = glyph_metrics.extents {

let w = glyph_metrics.unit_h_metrics.advance_width;
let h = extents.max.y - extents.min.y - face_metrics.descent as i32;

// large T
// if unicode == 0x0020 { space_height = h; }

if h > max_height { max_height = h; };

if h > max_height {
max_height = h;
};

total_width += w as u32;
cmap.insert(glyph_id, (unicode as u32, w as u32, h as u32));
Expand All @@ -251,9 +258,6 @@ impl ExternalFont {
}
}

let v_metrics = font.v_metrics_unscaled();
space_height = v_metrics.ascent /* - v_metrics.line_gap + v_metrics.descent + v_metrics.line_gap*/ as i32;

// Maps the character index to a unicode value
// Add this to the "ToUnicode" dictionary
// To explain this structure: Glyph IDs have to be in segments where the first byte of the
Expand Down Expand Up @@ -309,7 +313,7 @@ impl ExternalFont {
let mut current_width_vec = Vec::<Object>::new();

// scale the font width so that it sort-of fits into an 1000 unit square
let percentage_font_scaling = 1000.0 / (face.em_size() as f64);
let percentage_font_scaling = 1000.0 / (font.units_per_em() as f64);

for (gid, width) in widths {
if gid == current_high_gid {
Expand Down

0 comments on commit 9e037e3

Please sign in to comment.