Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ditch Reclutch for Skulpin #3

Merged
merged 6 commits into from
Sep 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Source code:
Fredrick Brennan (@ctrlcctrlv)
@jazzfool
Philip Degarmo (@aclysma) (src/opengl/imgui/support.rs - vendorized from Skulpin)

Design, icons:
Eli Heuer (@eliheuer)
16 changes: 6 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@ authors = ["Fredrick Brennan <copypaste@kittens.ph>"]

[dependencies]
# For display
reclutch = { git = "https://github.com/jazzfool/reclutch", features = ["skia"] }
imgui-glium-renderer = "0.4.0"
# We might need to vendorize these some day. See aclysma/skulpin#66:
# https://github.com/aclysma/skulpin/issues/66#issuecomment-689244118
skulpin = { version = "0.10.0", default-features = false, features = ["skia_complete", "skulpin_winit"] }
skulpin-plugin-imgui = "0.5.0"
imgui-winit-support = "0.4.0"
imgui = "0.4.0"
gl = "0.14.0"
glium = "0.27.0"

# For choosing font for toolbox
font-kit = "0.10.0"

# For icons in toolbox
nsvg = "0.5.1"

# For global state
lazy_static = "1.4.0"

Expand All @@ -36,5 +32,5 @@ colored = "2.0.0"

## Our crates
# parses .glif files and gives us a place to put arbitrary data
#glifparser = { git = "https://github.com/mfeq/glifparser" }
glifparser = { path = "../glifparser" } # for development
glifparser = { git = "https://github.com/mfeq/glifparser" }
#glifparser = { path = "../glifparser" } # for development
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ Two OpenGL contexts are made: one for Skia and one for Dear ImGui. Skia is redra

To make this as easy as possible to build, and cross-platform without hassle, the SVG icons are compiled right into the binary via the Rust `include_str!` macro.

### Mac users

Apple charges a fee to "notarize" applications and without this "notarization" Qglif will not run correctly, or in some cases, at all. So, for the foreseeable future, you must _build Qglif from source on OS X_. This is not as hard as it sounds! :-)

* Download and install the [Vulkan SDK](https://vulkan.lunarg.com/).
* Download and install [`rustup`](https://rustup.rs/), selecting the `nightly` toolchain.
* Pull this repository, and finally
* Run the below command to get started.

## Contributing

I typically build and run Qglif like this:
Expand Down
Binary file added resources/fonts/icons.ttf
Binary file not shown.
36 changes: 36 additions & 0 deletions resources/icons/gen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Run via gen.sh!
import fontforge
import psMat
import glob

font = fontforge.font()
font.fontname = font.familyname = font.fullname = "QglifIconFont"

WIDTH = 700

fn = open("../../src/imgui/icons.rs", "wb")

i = 0
for i, f in enumerate(glob.glob("*.svg")):
g = font.createChar(0xF000+i)
g.glyphname = f.split(".")[0]
s = psMat.compose(psMat.scale(0.7), psMat.translate(0, -(font.ascent / 7)))
g.importOutlines(f)
g.transform(s)
g.left_side_bearing = g.right_side_bearing = 0
equalize = int((WIDTH - g.width) / 2)
g.left_side_bearing = g.right_side_bearing = equalize
g.width = WIDTH
import sys
bytes_ = "[{}]".format(", ".join([str(i) for i in chr(0xF000+i).encode("utf-8")]+["0"]))
fn.write("pub const {}: &[u8] = &{}; // U+{:4X}\n".format(g.glyphname.upper(), bytes_, 0xF000+i).encode("ascii"))

fn.close()


font.encoding = "UnicodeBMP"
font.encoding = "compacted"
font.autoWidth(0)

font.save("icons.sfd")
font.generate("icons.ttf", flags=("no-hints", "no-flex", "omit-instructions"))
41 changes: 13 additions & 28 deletions resources/icons/gen.sh
Original file line number Diff line number Diff line change
@@ -1,36 +1,21 @@
#!/bin/bash
# Run as ./resources/icons/gen.sh !

OUTPUT=src/opengl/imgui/icons/data.rs

cd resources/icons
export PATH=/home/$USER/Workspace/fontforgebuilds/ReleasePackage:$PATH

cat << EOF > icons.rs
// SVG icons
// This file is automatically generated! See icons/gen.sh !
pub type SvgImageData = (u32, u32, Vec<u8>);

use nsvg;

use crate::STATE;

fn parse(name: &str, str: &'static str) -> SvgImageData {
let dpi = STATE.with(|v| v.borrow().dpi) * 96.;
debug!("Building SVG icons with DPI {}", dpi);
nsvg::parse_str(str, nsvg::Units::Pixel, dpi as f32)
.expect(&format!("Failed to parse SVG {}", name))
.rasterize_to_raw_rgba(0.75)
.expect(&format!("Failed to rasterize {}", name))
}
if [ -f `which run_fontforge` ]; then
DIR="$(dirname "`which run_fontforge`")"
FONTFORGE="$DIR/bin/fontforge.exe"
else
FONTFORGE=`which fontforge`
fi

EOF
>&2 echo "Fontforge is $FONTFORGE"
$FONTFORGE -quiet -lang=py -script gen.py

for f in *.svg; do
ICON_NAME=${f%.svg}
echo "const ${ICON_NAME^^}_ICON: &str = include_str!(concat!(env!(\"PWD\"), \"/\", \"resources/icons/$f\"));" >> icons.rs
printf "lazy_static! {\n pub static ref ${ICON_NAME^^}_ICON_IMAGE: SvgImageData = parse(stringify!($ICON_NAME), ${ICON_NAME^^}_ICON);\n}\n\n" >> icons.rs
done
if [ -z ../fonts ]; then
mkdir ../fonts
fi

cd ../..
mv resources/icons/icons.rs "$OUTPUT"
cargo fmt
mv icons.ttf ../fonts
124 changes: 35 additions & 89 deletions resources/icons/knife.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading