GeezerVison is showing github.com — Text display: letters alignment by farmaazon · Pull Request #62 · enso-org/ide
This repository was archived by the owner on Dec 28, 2021. It is now read-only.
Text display: letters alignment
#62
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
7e6194d
Displaying first char - untested
farmaazon Nov 19, 2019
7ed0490
Displaying a letter
farmaazon Nov 19, 2019
1b86cfe
Text component in workspace
farmaazon Nov 21, 2019
2a4e286
Much refactoring
farmaazon Nov 25, 2019
60dfe37
Tests WIP
farmaazon Nov 25, 2019
b05152c
WIP
farmaazon Nov 26, 2019
007b74f
Final touches
farmaazon Nov 26, 2019
76feca0
Merge branch 'master' into wip/ao/line-of-chars
farmaazon Nov 29, 2019
7d3256b
Review and linter fixes
farmaazon Nov 29, 2019
d48cb9d
Review
farmaazon Nov 29, 2019
b5c8445
Characters MSDF scaling and alignment
farmaazon Nov 27, 2019
cddd554
Kerning
farmaazon Nov 28, 2019
94d1051
WIP
farmaazon Nov 29, 2019
3d02253
Moved CachingIterator and fix tests
farmaazon Nov 29, 2019
2cd9e5a
Massive refactoring
farmaazon Dec 3, 2019
cc7ab1d
Lint suggestions
farmaazon Dec 3, 2019
4d4ae4b
Review fixes
farmaazon Dec 4, 2019
cd16f4f
Naming fix
farmaazon Dec 4, 2019
e11ace2
Remove the big file and fix tests
farmaazon Dec 4, 2019
98eaf0e
Merge branch 'master' into wip/ao/letters-alignment
farmaazon Dec 4, 2019
d327200
Fix compilation after merge
farmaazon Dec 4, 2019
File filter
Filter by extension
.glsl
(2)
.js
(1)
.rs
(17)
.toml
(3)
dotfile
(1)
All 5 file types selected
Only manifest files
Deleted files
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -3,32 +3,34 @@
use std::{fs, path};
use std::io::ErrorKind;
/// Download the release package from github
///
/// The project_url should be a project's main page on github.
pub fn github_download(
project_url : &str,
version : &str,
filename : &str,
destination_dir : &path::Path
) {
let url = format!(
"{project}/releases/download/{version}/{filename}",
project = project_url,
version = version,
filename = filename
);
/// A structure describing a concrete release package on github.
pub struct GithubRelease<Str:AsRef<str>> {
pub project_url : Str,
pub version : Str,
pub filename : Str,
}
let destination_file = path::Path::new(destination_dir)
.join(filename);
impl<Str:AsRef<str>> GithubRelease<Str> {
/// Download the release package from github
///
/// The project_url should be a project's main page on github.
pub fn download(&self, destination_dir:&path::Path) {
let url = format!(
"{project}/releases/download/{version}/{filename}",
project = self.project_url.as_ref(),
version = self.version.as_ref(),
filename = self.filename.as_ref());
let destination_dir_str = destination_dir.to_str().unwrap();
let destination_file = destination_dir.join(self.filename.as_ref());
let rm_error = fs::remove_file(&destination_file).err();
let fatal_rm_error =
rm_error.filter(|err| err.kind() != ErrorKind::NotFound);
fatal_rm_error.unwrap_none();
Self::remove_old_file(&destination_file);
download_lp::download(url.as_str(),destination_dir_str).unwrap();
}
download_lp::download(
url.as_str(),
destination_dir.to_str().unwrap()
).unwrap();
fn remove_old_file(file:&path::Path) {
let result = fs::remove_file(&file);
let error = result.err();
let fatal_error = error.filter(|err| err.kind() != ErrorKind::NotFound);
fatal_error.unwrap_none();
}
}
Original file line number
Diff line number
Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
package-lock.json
Original file line number
Diff line number
Diff line change
Expand Up
@@ -26,15 +26,14 @@ failure = { version = "0.1.5" }
derive_more = { version = "0.15.0" }
shrinkwraprs = { version = "0.2.1" }
itertools = { version = "0.8" }
nalgebra = { version = "0.18.1 " }
nalgebra = { version = "0.19.0 " }
bit_field = { version = "0.10.0" }
paste = { version = "0.1.6" }
enum_dispatch = { version = "= 0.1.3" } # https://gitlab.com/antonok/enum_dispatch/issues/10
typenum = { version = "1.11.2" }
rustc-hash = { version = "1.0.1" }
console_error_panic_hook = { version = "0.1.6" }
num_enum = { version = "0.4.2" }
smallvec = { version = "1.0.0" }
[dependencies.web-sys]
version = "0.3.4"
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -11,19 +11,17 @@ pub struct FillMapRsFile {
}
impl FillMapRsFile {
fn create<P: AsRef<path::Path>>(path : P) -> io::Result<FillMapRsFile> {
fn create<P:AsRef<path::Path>>(path: P) -> io::Result<FillMapRsFile> {
let mut file = fs::File::create(path)?;
writeln!(file, "{{")?;
Ok(FillMapRsFile{ file })
}
fn add_font_inserting_line(&mut self, font_name : &str, font_file : &str)
-> io::Result<()> {
writeln!(
self.file,
" fonts_by_name.insert(\"{}\", include_bytes!(\"{}\"));",
font_name,
font_file
fn add_font_inserting_line(&mut self, font_name:&str, font_file:&str) -> io::Result<()> {
writeln!(self.file,
" font_data_by_name.insert(\"{font_name}\", include_bytes!(\"{font_file}\"));",
font_name = font_name,
font_file = font_file
)
}
Expand All
@@ -37,38 +35,34 @@ impl FillMapRsFile {
// ====================
mod deja_vu {
use std::path;
use basegl_build_utilities::github_download;
use crate::FillMapRsFile;
pub const PACKAGE_NAME : &str = "dejavu-fonts-ttf-2.37.zip";
pub const PACKAGE_VERSION : &str = "version_2_37";
pub const PROJECT_URL : &str =
"https://github.com/dejavu-fonts/dejavu-fonts/";
use std::path;
use basegl_build_utilities::GithubRelease;
pub const PACKAGE : GithubRelease<&str> = GithubRelease {
project_url : "https://github.com/dejavu-fonts/dejavu-fonts/",
version : "version_2_37",
filename : "dejavu-fonts-ttf-2.37.zip"
};
pub const PACKAGE_FONTS_PREFIX: &str = "dejavu-fonts-ttf-2.37/ttf";
pub const PACKAGE_FONTS_PREFIX : &str = "dejavu-fonts-ttf-2.37/ttf";
pub fn font_file_from_font_name(font_name : &str) -> String {
pub fn font_file_from_font_name(font_name: &str) -> String {
return format!("{}.ttf", font_name);
}
pub fn extract_font(package_path : &path::Path, font_name : &str) {
let font_file = font_file_from_font_name(font_name);
let font_package_path = format!("{}/{}",
PACKAGE_FONTS_PREFIX,
font_file
);
let mut archive = zip::ZipArchive::new(
std::fs::File::open(package_path).unwrap()
).unwrap();
let mut input = archive.by_name(
font_package_path.as_str()
).unwrap();
let mut output = std::fs::File::create(
package_path.parent().unwrap().join(font_file)
).unwrap();
std::io::copy(&mut input, &mut output).unwrap();
pub fn extract_font(package_path:&path::Path, font_name:&str) {
let font_file = font_file_from_font_name(font_name);
let font_in_package_path = format!("{}/{}",PACKAGE_FONTS_PREFIX,font_file);
let package_dir = package_path.parent().unwrap();
let output_path = package_dir.join(font_file);
let archive_file = std::fs::File::open(package_path).unwrap();
let mut archive = zip::ZipArchive::new(archive_file).unwrap();
let mut input_stream = archive.by_name(font_in_package_path.as_str()).unwrap();
let mut output_stream = std::fs::File::create(output_path).unwrap();
std::io::copy(&mut input_stream, &mut output_stream).unwrap();
}
pub const FONTS_TO_EXTRACT : &[&str] = &[
Expand All
@@ -79,8 +73,7 @@ mod deja_vu {
"DejaVuSansMono-Oblique",
"DejaVuSansCondensed",
"DejaVuSerif",
"DejaVuSerifCondensed",
];
"DejaVuSerifCondensed" ];
pub fn extract_all_fonts(package_path : &path::Path) {
for font_name in FONTS_TO_EXTRACT {
Expand All
@@ -89,35 +82,27 @@ mod deja_vu {
}
pub fn download_and_extract_all_fonts(out_dir : &path::Path) {
github_download(
PROJECT_URL,
PACKAGE_VERSION,
PACKAGE_NAME,
&out_dir
);
let package_path = out_dir.join(PACKAGE_NAME);
let package_path = out_dir.join(PACKAGE.filename);
PACKAGE.download(&out_dir);
extract_all_fonts(package_path.as_path());
}
pub fn add_entries_to_fill_map_rs(file : &mut FillMapRsFile) {
pub fn add_entries_to_fill_map_rs(file: &mut FillMapRsFile) {
for font_name in FONTS_TO_EXTRACT {
let font_file = font_file_from_font_name(font_name);
file.add_font_inserting_line(
font_name,
font_file.as_str()
).unwrap();
file.add_font_inserting_line(font_name,font_file.as_str()).unwrap();
}
}
}
fn main() {
let out = env::var("OUT_DIR").unwrap();
let out_dir = path::Path::new(&out);
let fill_map_rs_path = out_dir.join("fill_map.rs");
let out = env::var("OUT_DIR").unwrap();
let out_dir = path::Path::new(&out);
let fill_map_rs_path = out_dir.join("fill_map.rs");
let mut fill_map_rs_file =
FillMapRsFile::create(fill_map_rs_path).unwrap();
let mut fill_map_rs_file = FillMapRsFile::create(fill_map_rs_path).unwrap();
deja_vu::download_and_extract_all_fonts(out_dir);
deja_vu::add_entries_to_fill_map_rs(&mut fill_map_rs_file);
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -7,7 +7,7 @@ use basegl_prelude::*;
///
/// For list of embedded fonts, see FONTS_TO_EXTRACT constant in `build.rs`
pub struct EmbeddedFonts {
pub font_data_by_name: HashMap<&'static str, &'static [u8]>
pub font_data_by_name: HashMap<&'static str,&'static [u8]>
}
impl EmbeddedFonts {
Expand All
@@ -16,23 +16,21 @@ impl EmbeddedFonts {
/// For list of embedded fonts, see `FONTS_TO_EXTRACT` constant in
/// `build.rs`
pub fn create_and_fill() -> EmbeddedFonts {
let mut fonts_by_name : HashMap<&'static str, &'static [u8]>
= HashMap::new();
let mut font_data_by_name = HashMap::<&'static str,&'static [u8]>::new();
include!(concat!(env!("OUT_DIR"), "/fill_map.rs"));
EmbeddedFonts {
font_data_by_name: fonts_by_name
}
EmbeddedFonts{font_data_by_name}
}
}
#[cfg(test)]
mod test {
use crate::EmbeddedFonts ;
use crate::* ;
#[test]
fn loading_embedded_fonts() {
let fonts = EmbeddedFonts::create_and_fill();
let fonts = EmbeddedFonts::create_and_fill();
let example_font = fonts.font_data_by_name.get("DejaVuSans").unwrap();
assert_eq!(0x00, example_font[0]);
assert_eq!(0x01, example_font[1]);
assert_eq!(0x1d, example_font[example_font.len()-1]);
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -10,7 +10,7 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
wasm-bindgen = "0.2.53"
js-sys = "0.3.30"
vector2d = "2.2 .0"
nalgebra = "0.19 .0"
basegl-prelude = { version = "0.1.0", path="../../prelude" }
[dev-dependencies]
Expand Down
Original file line number
Diff line number
Diff line change
@@ -1,21 +1,20 @@
use basegl_build_utilities::github_download;
mod msdfgen_wasm {
use crate::github_download;
use std::{path, fs};
use basegl_build_utilities::GithubRelease;
use std::{path,fs};
use std::io::Write;
pub const VERSION : &str = "v1.0.1";
pub const FILENAME : &str = "msdfgen_wasm.js";
pub const PROJECT_URL : &str = "https://github.com/luna/msdfgen-wasm";
pub const PACKAGE : GithubRelease<&str> = GithubRelease {
project_url : "https://github.com/luna/msdfgen-wasm",
version : "v1.1",
filename : "msdfgen_wasm.js"
};
pub const FILENAME : &str = PACKAGE.filename;
pub fn download() {
github_download(
PROJECT_URL,
VERSION,
FILENAME,
path::Path::new(".") // Note [Downloading to src dir]
)
PACKAGE.download(path::Path::new(".")) // Note [Downloading to src dir]
}
/* Note [Downloading to src dir]
Expand All
@@ -30,8 +29,10 @@ mod msdfgen_wasm {
* remember to remove msdfgen_wasm.js entry from .gitignore
*/
const PATCH_LINE : &str = "; export { ccall, getValue, \
_msdfgen_maxMSDFSize, _msdfgen_generateMSDF, _msdfgen_freeFont, \
const PATCH_LINE : &str = "; export { ccall, getValue, _msdfgen_getKerning,\
_msdfgen_generateAutoframedMSDF, _msdfgen_result_getMSDFData,\
_msdfgen_result_getAdvance, _msdfgen_result_getTranslation,\
_msdfgen_result_getScale, _msdfgen_freeResult, _msdfgen_freeFont,\
addInitializationCb, isInitialized }";
/// Patches downloaded msdfgen_wasm.js file
Expand All
@@ -40,7 +41,11 @@ mod msdfgen_wasm {
/// be explicitly exported. Examples works without this line perfectly.
pub fn patch_for_wasm_bindgen_test() {
let path = path::Path::new(FILENAME);
let mut file = fs::OpenOptions::new().append(true).open(path).unwrap();
let mut open_options = fs::OpenOptions::new();
open_options.append(true);
let mut file = open_options.open(path).unwrap();
file.write(PATCH_LINE.as_bytes()).unwrap();
}
}
Expand Down
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.