mirror of
https://github.com/itsjunetime/tdf.git
synced 2026-06-01 23:51:46 -04:00
Custom Colors (#70)
* First implementation of custom colors * Remove use-statement Co-authored-by: June <61218022+itsjunetime@users.noreply.github.com> * Cleaned up help-text Co-authored-by: June <61218022+itsjunetime@users.noreply.github.com> * Removed superfluous features from csscolorparser * Fix for clippy * Clarify how to pass in custom colors * Explicitly install clippy and rustfmt in CI * Better error handling when colors can not be parsed Co-authored-by: June <61218022+itsjunetime@users.noreply.github.com> * More elegant type conversion Co-authored-by: June <61218022+itsjunetime@users.noreply.github.com> * Made clippy happy --------- Co-authored-by: June <61218022+itsjunetime@users.noreply.github.com> Co-authored-by: itsjunetime <junewelker@gmail.com>
This commit is contained in:
@@ -9,5 +9,5 @@ async fn main() {
|
||||
.nth(1)
|
||||
.expect("Please enter a file to profile");
|
||||
|
||||
utils::render_doc(file, None).await;
|
||||
utils::render_doc(file, None, 0, 1000).await;
|
||||
}
|
||||
|
||||
+12
-9
@@ -23,11 +23,14 @@ const FILES: [&str; 3] = [
|
||||
"benches/geotopo.pdf"
|
||||
];
|
||||
|
||||
const BLACK: i32 = 0;
|
||||
const WHITE: i32 = 1000;
|
||||
|
||||
fn render_full(c: &mut Criterion) {
|
||||
for file in FILES {
|
||||
c.bench_with_input(BenchmarkId::new("render_full", file), &file, |b, &file| {
|
||||
b.to_async(tokio::runtime::Runtime::new().unwrap())
|
||||
.iter(|| render_doc(file, None))
|
||||
.iter(|| render_doc(file, None, BLACK, WHITE))
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -39,7 +42,7 @@ fn render_to_first_page(c: &mut Criterion) {
|
||||
&file,
|
||||
|b, &file| {
|
||||
b.to_async(tokio::runtime::Runtime::new().unwrap())
|
||||
.iter(|| render_first_page(file))
|
||||
.iter(|| render_first_page(file, BLACK, WHITE))
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -48,7 +51,7 @@ fn render_to_first_page(c: &mut Criterion) {
|
||||
fn only_converting(c: &mut Criterion) {
|
||||
for file in FILES {
|
||||
let runtime = tokio::runtime::Runtime::new().unwrap();
|
||||
let all_rendered = runtime.block_on(render_all_files(file));
|
||||
let all_rendered = runtime.block_on(render_all_files(file, BLACK, WHITE));
|
||||
|
||||
c.bench_with_input(
|
||||
BenchmarkId::new("only_converting", file),
|
||||
@@ -68,7 +71,7 @@ fn search_short_common(c: &mut Criterion) {
|
||||
&file,
|
||||
|b, &file| {
|
||||
b.to_async(tokio::runtime::Runtime::new().unwrap())
|
||||
.iter(|| render_doc(file, Some("an")))
|
||||
.iter(|| render_doc(file, Some("an"), BLACK, WHITE))
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -81,20 +84,20 @@ fn search_long_rare(c: &mut Criterion) {
|
||||
&file,
|
||||
|b, &file| {
|
||||
b.to_async(tokio::runtime::Runtime::new().unwrap())
|
||||
.iter(|| render_doc(file, Some("this is long and rare")))
|
||||
.iter(|| render_doc(file, Some("this is long and rare"), BLACK, WHITE))
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn render_first_page(path: impl AsRef<Path>) {
|
||||
pub async fn render_first_page(path: impl AsRef<Path>, black: i32, white: i32) {
|
||||
let RenderState {
|
||||
mut from_render_rx,
|
||||
mut from_converter_rx,
|
||||
mut pages,
|
||||
mut to_converter_tx,
|
||||
to_render_tx
|
||||
} = start_all_rendering(path);
|
||||
} = start_all_rendering(path, black, white);
|
||||
|
||||
// we only want to render until the first page is ready to be printed
|
||||
while pages.iter().all(Option::is_none) {
|
||||
@@ -114,8 +117,8 @@ pub async fn render_first_page(path: impl AsRef<Path>) {
|
||||
drop(to_render_tx);
|
||||
}
|
||||
|
||||
async fn render_all_files(path: &'static str) -> Vec<PageInfo> {
|
||||
let (mut from_render_rx, to_render_tx) = start_rendering_loop(path);
|
||||
async fn render_all_files(path: &'static str, black: i32, white: i32) -> Vec<PageInfo> {
|
||||
let (mut from_render_rx, to_render_tx) = start_rendering_loop(path, black, white);
|
||||
let mut pages = Vec::<Option<PageInfo>>::new();
|
||||
|
||||
while let Some(info) = from_render_rx.next().await {
|
||||
|
||||
+10
-6
@@ -57,7 +57,9 @@ pub struct RenderState {
|
||||
const FONT_SIZE: (u16, u16) = (8, 14);
|
||||
|
||||
pub fn start_rendering_loop(
|
||||
path: impl AsRef<Path>
|
||||
path: impl AsRef<Path>,
|
||||
black: i32,
|
||||
white: i32
|
||||
) -> (
|
||||
RecvStream<'static, Result<RenderInfo, RenderError>>,
|
||||
Sender<RenderNotif>
|
||||
@@ -91,7 +93,9 @@ pub fn start_rendering_loop(
|
||||
to_main_tx,
|
||||
from_main_rx,
|
||||
size,
|
||||
tdf::PrerenderLimit::All
|
||||
tdf::PrerenderLimit::All,
|
||||
black,
|
||||
white
|
||||
)
|
||||
});
|
||||
|
||||
@@ -122,8 +126,8 @@ pub fn start_converting_loop(
|
||||
(from_converter_rx, to_converter_tx)
|
||||
}
|
||||
|
||||
pub fn start_all_rendering(path: impl AsRef<Path>) -> RenderState {
|
||||
let (from_render_rx, to_render_tx) = start_rendering_loop(path);
|
||||
pub fn start_all_rendering(path: impl AsRef<Path>, black: i32, white: i32) -> RenderState {
|
||||
let (from_render_rx, to_render_tx) = start_rendering_loop(path, black, white);
|
||||
let (from_converter_rx, to_converter_tx) = start_converting_loop(20);
|
||||
|
||||
let pages: Vec<Option<ConvertedPage>> = Vec::new();
|
||||
@@ -137,14 +141,14 @@ pub fn start_all_rendering(path: impl AsRef<Path>) -> RenderState {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn render_doc(path: impl AsRef<Path>, search_term: Option<&str>) {
|
||||
pub async fn render_doc(path: impl AsRef<Path>, search_term: Option<&str>, black: i32, white: i32) {
|
||||
let RenderState {
|
||||
mut from_render_rx,
|
||||
mut from_converter_rx,
|
||||
mut pages,
|
||||
mut to_converter_tx,
|
||||
to_render_tx
|
||||
} = start_all_rendering(path);
|
||||
} = start_all_rendering(path, black, white);
|
||||
|
||||
if let Some(term) = search_term {
|
||||
to_render_tx
|
||||
|
||||
Reference in New Issue
Block a user