Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf588528ca | ||
|
|
db98ba627b | ||
|
|
479b7196cf | ||
|
|
a338ff02f1 | ||
|
|
f9b29d4645 | ||
|
|
33f1984862 | ||
|
|
c2318f9929 | ||
|
|
1648aa5736 | ||
|
|
43b20ecd0d | ||
|
|
fff5aa8596 | ||
|
|
032a450d7e | ||
|
|
0881080b3f | ||
|
|
07784a848c | ||
|
|
bdf128addc | ||
|
|
7e7b4a75c8 | ||
|
|
f5954446d1 | ||
|
|
e6bdba1137 |
No files matched your search
+42
-1
@@ -2,6 +2,43 @@
|
||||
|
||||
## [Unreleased] - ReleaseDate
|
||||
|
||||
## [0.2.5] - 2025-10-30
|
||||
|
||||
### Added
|
||||
|
||||
- Add support for "faux italics"
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix crash that occurs due to surface format selection not filtering out formats that require unrequested GPU features
|
||||
|
||||
## [0.2.4] - 2025-10-30
|
||||
|
||||
### Added
|
||||
|
||||
- Add support for loading webp images
|
||||
- Add support for new 'fontin' fonts
|
||||
|
||||
### Changed
|
||||
|
||||
- Use `~/.local/share/RustyPathOfBuilding{1,2}/userdata` as default location for settings and build files. Builds files created prior to this change need to be manually copied from the old location in `~/Documents/`. Sorry about the inconvenience.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix scrolling of gem selection dropdown
|
||||
|
||||
## [0.2.3] - 2025-10-29
|
||||
|
||||
### Added
|
||||
|
||||
- Add exponential backoff for github requests
|
||||
|
||||
## [0.2.2] - 2025-10-29
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix version file
|
||||
|
||||
## [0.2.1] - 2025-10-28
|
||||
|
||||
### Added
|
||||
@@ -56,8 +93,12 @@
|
||||
- First release
|
||||
|
||||
<!-- next-url -->
|
||||
[Unreleased]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.1...HEAD
|
||||
[Unreleased]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.5...HEAD
|
||||
|
||||
[0.2.5]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.4...v0.2.5
|
||||
[0.2.4]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.3...v0.2.4
|
||||
[0.2.3]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.2...v0.2.3
|
||||
[0.2.2]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.1...v0.2.2
|
||||
[0.2.1]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.0...v0.2.1
|
||||
[0.2.0]: https://github.com/meehl/rusty-path-of-building/compare/v0.1.2...v0.2.0
|
||||
[0.1.2]: https://github.com/meehl/rusty-path-of-building/compare/v0.1.1...v0.1.2
|
||||
|
||||
Generated
+12
-1
@@ -1120,6 +1120,7 @@ checksum = "529feb3e6769d234375c4cf1ee2ce713682b8e76538cb13f9fc23e1400a591e7"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"byteorder-lite",
|
||||
"image-webp",
|
||||
"moxcms",
|
||||
"num-traits",
|
||||
"png",
|
||||
@@ -1129,6 +1130,16 @@ dependencies = [
|
||||
"zune-jpeg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "image-webp"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "525e9ff3e1a4be2fbea1fdf0e98686a6d98b4d8f937e1bf7402245af1909e8c3"
|
||||
dependencies = [
|
||||
"byteorder-lite",
|
||||
"quick-error",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "imgref"
|
||||
version = "1.12.0"
|
||||
@@ -2519,7 +2530,7 @@ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
||||
|
||||
[[package]]
|
||||
name = "rusty-path-of-building"
|
||||
version = "0.2.1"
|
||||
version = "0.2.5"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"anyhow",
|
||||
|
||||
+2
-2
@@ -4,7 +4,7 @@ authors = ["meehl"]
|
||||
description = "Cross-platform runtime for Path of Building"
|
||||
repository = "https://github.com/meehl/rusty-path-of-building"
|
||||
license = "MIT"
|
||||
version = "0.2.1"
|
||||
version = "0.2.5"
|
||||
edition = "2024"
|
||||
publish = false
|
||||
|
||||
@@ -21,7 +21,7 @@ euclid = { version = "0.22.11", features = ["bytemuck"] }
|
||||
fast_image_resize = { version = "5.3.0", features = ["image"] }
|
||||
flate2 = "1.1.2"
|
||||
glob = "0.3.3"
|
||||
image = { version = "0.25.8", default-features = false, features = ["rayon", "jpeg", "png"] }
|
||||
image = { version = "0.25.8", default-features = false, features = ["rayon", "jpeg", "png", "webp"] }
|
||||
log = "0.4"
|
||||
mlua = { version = "0.11.2", features = ["luajit", "anyhow"] }
|
||||
nohash-hasher = "0.2.0"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
Rusty Path of Building is a cross-platform runtime for [Path of Building](https://github.com/PathOfBuildingCommunity/PathOfBuilding) and [Path of Building 2](https://github.com/PathOfBuildingCommunity/PathOfBuilding-PoE2). Like the [official runtime](https://github.com/PathOfBuildingCommunity/PathOfBuilding-SimpleGraphic), it serves as a host environment for PoB by implementing the API used by the application's Lua logic, as well as rendering, window management, and input handling.
|
||||
|
||||
This project was primarily created to allow Path of Building to run natively on Linux. It is written in Rust (in case you couldn't already tell from the unimaginative name) and is designed to work across all platforms, though only Linux has been tested so far.
|
||||
This project was primarily created to allow Path of Building to run natively on Linux. It is written in Rust (in case you couldn't already tell from the unimaginative name) and should run on all platforms, though only Linux has been tested so far.
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -10,8 +10,6 @@ This project was primarily created to allow Path of Building to run natively on
|
||||
rusty-path-of-building [poe1|poe2]
|
||||
```
|
||||
|
||||
NOTE: The first run takes a bit longer because Path of Building's assets need to be downloaded.
|
||||
|
||||
## Installation
|
||||
|
||||
### Arch (AUR)
|
||||
@@ -34,6 +32,7 @@ Path of Building's Lua code requires the following C libraries:
|
||||
|
||||
- [Lua-cURLv3](https://github.com/Lua-cURL/Lua-cURLv3)
|
||||
- [luautf8](https://github.com/starwing/luautf8)
|
||||
- [luasocket](https://github.com/lunarmodules/luasocket)
|
||||
- `lzip` - The source is included in this repo under `lua/libs/lzip` and requires [zlib](https://www.zlib.net/) to compile. Build it with `make LUA_IMPL=luajit`.
|
||||
|
||||
Please refer to the [Lua documentation](https://www.lua.org/manual/5.1/manual.html#pdf-package.cpath) to see how it locates libraries.
|
||||
|
||||
Binary file not shown.
Binary file not shown.
+2
-14
@@ -1,5 +1,3 @@
|
||||
use anyhow::anyhow;
|
||||
use directories::UserDirs;
|
||||
use mlua::{IntoLuaMulti, Lua, MultiValue, Result as LuaResult, Value};
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
@@ -9,18 +7,8 @@ use crate::{
|
||||
util::{change_working_directory, get_executable_dir},
|
||||
};
|
||||
|
||||
pub fn get_user_path(_: &Lua, _: ()) -> LuaResult<anyhow::Result<PathBuf>> {
|
||||
let user_dirs = match UserDirs::new() {
|
||||
Some(user_dirs) => user_dirs,
|
||||
None => return Ok(Err(anyhow!("Failed to retrieve user's home directory"))),
|
||||
};
|
||||
|
||||
match user_dirs.document_dir() {
|
||||
Some(docs_dir) => Ok(Ok(docs_dir.canonicalize().unwrap())),
|
||||
None => Ok(Err(anyhow!(
|
||||
"Failed to retrieve user's documents directory"
|
||||
))),
|
||||
}
|
||||
pub fn get_user_path(_: &Lua, _: ()) -> LuaResult<PathBuf> {
|
||||
Ok(Game::user_data_dir())
|
||||
}
|
||||
|
||||
// parent directory of Launch.lua script
|
||||
|
||||
+21
-5
@@ -2,7 +2,7 @@ use crate::{
|
||||
api::image_handle::ImageHandle,
|
||||
color::Srgba,
|
||||
dpi::Uv,
|
||||
fonts::{Alignment, LayoutJob},
|
||||
fonts::{Alignment, FontStyle, LayoutJob},
|
||||
lua::ContextSocket,
|
||||
math::{Point, Quad, Rect, Size},
|
||||
};
|
||||
@@ -11,8 +11,9 @@ use mlua::{
|
||||
LightUserData, Lua, Result as LuaResult, UserDataRefMut, Value,
|
||||
ffi::{self},
|
||||
};
|
||||
use parley::FontFamily;
|
||||
use regex::Regex;
|
||||
use std::sync::LazyLock;
|
||||
use std::{borrow::Cow, sync::LazyLock};
|
||||
|
||||
pub fn register_globals(lua: &Lua) -> LuaResult<()> {
|
||||
let globals = lua.globals();
|
||||
@@ -467,12 +468,20 @@ fn build_layout_job<'a>(
|
||||
alignment: Option<Alignment>,
|
||||
) -> LayoutJob<'a> {
|
||||
let mut font_weight = None;
|
||||
let mut font_style = FontStyle::default();
|
||||
let font_family = match font_type {
|
||||
PoBFontType::Fixed => parley::GenericFamily::Monospace,
|
||||
PoBFontType::Var => parley::GenericFamily::SansSerif,
|
||||
PoBFontType::Fixed => FontFamily::Named(Cow::Borrowed("Bitstream Vera Sans Mono")),
|
||||
PoBFontType::Var => FontFamily::Named(Cow::Borrowed("Liberation Sans")),
|
||||
PoBFontType::VarBold => {
|
||||
font_weight = Some(700.0);
|
||||
parley::GenericFamily::SansSerif
|
||||
FontFamily::Named(Cow::Borrowed("Liberation Sans"))
|
||||
}
|
||||
PoBFontType::FontinItalic => FontFamily::Named(Cow::Borrowed("Fontin")),
|
||||
PoBFontType::FontinSmallcaps => FontFamily::Named(Cow::Borrowed("Fontin SmallCaps")),
|
||||
PoBFontType::FontinSmallcapsItalic => {
|
||||
font_style = FontStyle::Italic;
|
||||
// use regular Smallcaps with "faux italics"
|
||||
FontFamily::Named(Cow::Borrowed("Fontin SmallCaps"))
|
||||
}
|
||||
};
|
||||
|
||||
@@ -485,6 +494,7 @@ fn build_layout_job<'a>(
|
||||
line_height as f32,
|
||||
alignment,
|
||||
font_weight,
|
||||
font_style,
|
||||
);
|
||||
|
||||
for (color, segment) in PoBString(text).into_iter() {
|
||||
@@ -622,6 +632,9 @@ enum PoBFontType {
|
||||
Fixed,
|
||||
Var,
|
||||
VarBold,
|
||||
FontinSmallcaps,
|
||||
FontinSmallcapsItalic,
|
||||
FontinItalic,
|
||||
}
|
||||
|
||||
impl std::str::FromStr for PoBFontType {
|
||||
@@ -632,6 +645,9 @@ impl std::str::FromStr for PoBFontType {
|
||||
"FIXED" => Ok(Self::Fixed),
|
||||
"VAR" => Ok(Self::Var),
|
||||
"VAR BOLD" => Ok(Self::VarBold),
|
||||
"FONTIN SC" => Ok(Self::FontinSmallcaps),
|
||||
"FONTIN SC ITALIC" => Ok(Self::FontinSmallcapsItalic),
|
||||
"FONTIN ITALIC" => Ok(Self::FontinItalic),
|
||||
_ => Err(anyhow::anyhow!(
|
||||
"'{}' is not a valid TextFontType variant",
|
||||
s
|
||||
|
||||
+57
-2
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
dpi::{ConvertToLogical, PhysicalPoint, PhysicalSize},
|
||||
fonts::Fonts,
|
||||
fonts::{FontData, FontDefinitions, Fonts},
|
||||
gfx::{GraphicsContext, RenderJob},
|
||||
input::InputState,
|
||||
installer::InstallMode,
|
||||
@@ -54,7 +54,7 @@ impl App {
|
||||
state: AppState {
|
||||
window: WindowState::default(),
|
||||
input: InputState::default(),
|
||||
fonts: Fonts::new(),
|
||||
fonts: Fonts::new(pob_font_definitions()),
|
||||
texture_manager: WrappedTextureManager::new(),
|
||||
clipboard: arboard::Clipboard::new()?,
|
||||
},
|
||||
@@ -277,3 +277,58 @@ impl ApplicationHandler<GraphicsContext> for App {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn pob_font_definitions() -> FontDefinitions {
|
||||
let mut definitions = FontDefinitions::default();
|
||||
|
||||
definitions.font_data.insert(
|
||||
"bitstream-vera-sans-mono".to_owned(),
|
||||
Arc::new(FontData::from_static(include_bytes!(
|
||||
"../fonts/VeraMono.ttf"
|
||||
))),
|
||||
);
|
||||
definitions.font_data.insert(
|
||||
"liberation-sans".to_owned(),
|
||||
Arc::new(FontData::from_static(include_bytes!(
|
||||
"../fonts/LiberationSans-Regular.ttf"
|
||||
))),
|
||||
);
|
||||
definitions.font_data.insert(
|
||||
"liberation-sans-bold".to_owned(),
|
||||
Arc::new(FontData::from_static(include_bytes!(
|
||||
"../fonts/LiberationSans-Bold.ttf"
|
||||
))),
|
||||
);
|
||||
definitions.font_data.insert(
|
||||
"fontin-italic".to_owned(),
|
||||
Arc::new(FontData::from_static(include_bytes!(
|
||||
"../fonts/fontin-italic.ttf"
|
||||
))),
|
||||
);
|
||||
definitions.font_data.insert(
|
||||
"fontin-smallcaps".to_owned(),
|
||||
Arc::new(FontData::from_static(include_bytes!(
|
||||
"../fonts/fontin-smallcaps.ttf"
|
||||
))),
|
||||
);
|
||||
|
||||
definitions.generic_families.insert(
|
||||
parley::GenericFamily::Monospace,
|
||||
vec!["bitstream-vera-sans-mono".to_owned()],
|
||||
);
|
||||
|
||||
definitions.generic_families.insert(
|
||||
parley::GenericFamily::SansSerif,
|
||||
vec![
|
||||
"liberation-sans".to_owned(),
|
||||
"liberation-sans-bold".to_owned(),
|
||||
],
|
||||
);
|
||||
|
||||
definitions.generic_families.insert(
|
||||
parley::GenericFamily::Serif,
|
||||
vec!["fontin-italic".to_owned(), "fontin-smallcaps".to_owned()],
|
||||
);
|
||||
|
||||
definitions
|
||||
}
|
||||
+9
-1
@@ -31,11 +31,19 @@ impl Game {
|
||||
GAME_CONFIG.get().expect("Game should be initialized")
|
||||
}
|
||||
|
||||
pub fn script_dir() -> PathBuf {
|
||||
pub fn data_dir() -> PathBuf {
|
||||
let directory_name = match Self::current() {
|
||||
Game::Poe1 => "RustyPathOfBuilding1",
|
||||
Game::Poe2 => "RustyPathOfBuilding2",
|
||||
};
|
||||
BaseDirs::new().unwrap().data_dir().join(directory_name)
|
||||
}
|
||||
|
||||
pub fn script_dir() -> PathBuf {
|
||||
Game::data_dir()
|
||||
}
|
||||
|
||||
pub fn user_data_dir() -> PathBuf {
|
||||
Game::data_dir().join("userdata")
|
||||
}
|
||||
}
|
||||
+49
-42
@@ -7,24 +7,24 @@ use crate::{
|
||||
renderer::image::ImageDelta,
|
||||
util::calculate_hash,
|
||||
};
|
||||
use ahash::HashMap;
|
||||
use ordered_float::OrderedFloat;
|
||||
use parley::{
|
||||
FontContext, FontWeight, GenericFamily, LayoutContext, StyleProperty, TextStyle, fontique::Blob,
|
||||
FontContext, FontFamily, FontStack, FontWeight, GenericFamily, LayoutContext, StyleProperty,
|
||||
TextStyle, fontique::Blob,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub use atlas::FontAtlasSize;
|
||||
pub use layout::{Alignment, Layout, LayoutJob};
|
||||
pub use layout::{Alignment, FontStyle, Layout, LayoutJob};
|
||||
|
||||
mod atlas;
|
||||
mod glyph_key;
|
||||
mod layout;
|
||||
mod rasterizer;
|
||||
|
||||
pub const BITSTREAM_VERA_SANS_MONO: &[u8] = include_bytes!("../fonts/VeraMono.ttf");
|
||||
pub const LIBERATION_SANS: &[u8] = include_bytes!("../fonts/LiberationSans-Regular.ttf");
|
||||
pub const LIBERATION_SANS_BOLD: &[u8] = include_bytes!("../fonts/LiberationSans-Bold.ttf");
|
||||
|
||||
/// Data of a .ttf or .otf file
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct FontData {
|
||||
data: std::borrow::Cow<'static, [u8]>,
|
||||
}
|
||||
@@ -43,13 +43,14 @@ impl AsRef<[u8]> for FontData {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FontDefinition {
|
||||
pub generic_families: Vec<GenericFamily>,
|
||||
pub data: Arc<FontData>,
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct FontDefinitions {
|
||||
pub font_data: HashMap<String, Arc<FontData>>,
|
||||
pub generic_families: HashMap<GenericFamily, Vec<String>>,
|
||||
}
|
||||
|
||||
pub struct Fonts {
|
||||
font_definitions: Vec<FontDefinition>,
|
||||
definitions: FontDefinitions,
|
||||
font_context: FontContext,
|
||||
layout_context: LayoutContext<Srgba>,
|
||||
atlas: FontAtlas,
|
||||
@@ -58,25 +59,9 @@ pub struct Fonts {
|
||||
}
|
||||
|
||||
impl Fonts {
|
||||
pub fn new() -> Self {
|
||||
// add fonts used by PoB
|
||||
let font_definitions = vec![
|
||||
FontDefinition {
|
||||
generic_families: vec![GenericFamily::Monospace],
|
||||
data: Arc::new(FontData::from_static(BITSTREAM_VERA_SANS_MONO)),
|
||||
},
|
||||
FontDefinition {
|
||||
generic_families: vec![GenericFamily::SansSerif],
|
||||
data: Arc::new(FontData::from_static(LIBERATION_SANS)),
|
||||
},
|
||||
FontDefinition {
|
||||
generic_families: vec![GenericFamily::SansSerif],
|
||||
data: Arc::new(FontData::from_static(LIBERATION_SANS_BOLD)),
|
||||
},
|
||||
];
|
||||
|
||||
pub fn new(definitions: FontDefinitions) -> Self {
|
||||
let mut fonts = Self {
|
||||
font_definitions,
|
||||
definitions,
|
||||
font_context: FontContext::new(),
|
||||
layout_context: LayoutContext::new(),
|
||||
atlas: FontAtlas::new(1024),
|
||||
@@ -92,14 +77,20 @@ impl Fonts {
|
||||
}
|
||||
|
||||
fn register_fonts(&mut self) {
|
||||
for definition in &self.font_definitions {
|
||||
let blob = Blob::new(Arc::new(definition.data.data.clone()));
|
||||
let registered_fonts = self.font_context.collection.register_fonts(blob, None);
|
||||
for generic_family in &definition.generic_families {
|
||||
self.font_context
|
||||
.collection
|
||||
.append_generic_families(*generic_family, registered_fonts.iter().map(|f| f.0));
|
||||
}
|
||||
for data in self.definitions.font_data.values() {
|
||||
let blob = Blob::new(Arc::new(data.data.clone()));
|
||||
self.font_context.collection.register_fonts(blob, None);
|
||||
}
|
||||
|
||||
for (generic_family, family_fonts) in &self.definitions.generic_families {
|
||||
let family_ids: Vec<_> = family_fonts
|
||||
.iter()
|
||||
.filter_map(|family_name| self.font_context.collection.family_id(family_name))
|
||||
.collect();
|
||||
|
||||
self.font_context
|
||||
.collection
|
||||
.set_generic_families(*generic_family, family_ids.into_iter());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,13 +119,26 @@ impl Fonts {
|
||||
common_chars.push(c as char);
|
||||
}
|
||||
|
||||
self.preload_text(&common_chars, font_size, GenericFamily::Monospace, None);
|
||||
self.preload_text(&common_chars, font_size, GenericFamily::SansSerif, None);
|
||||
self.preload_text(
|
||||
&common_chars,
|
||||
font_size,
|
||||
GenericFamily::SansSerif,
|
||||
FontFamily::Generic(GenericFamily::Monospace),
|
||||
None,
|
||||
parley::FontStyle::Normal,
|
||||
);
|
||||
self.preload_text(
|
||||
&common_chars,
|
||||
font_size,
|
||||
FontFamily::Generic(GenericFamily::SansSerif),
|
||||
None,
|
||||
parley::FontStyle::Normal,
|
||||
);
|
||||
self.preload_text(
|
||||
&common_chars,
|
||||
font_size,
|
||||
FontFamily::Generic(GenericFamily::SansSerif),
|
||||
Some(FontWeight::BOLD),
|
||||
parley::FontStyle::Normal,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -142,14 +146,16 @@ impl Fonts {
|
||||
&mut self,
|
||||
text: &str,
|
||||
font_size: f32,
|
||||
generic_family: GenericFamily,
|
||||
font_family: FontFamily,
|
||||
font_weight: Option<FontWeight>,
|
||||
font_style: parley::FontStyle,
|
||||
) {
|
||||
profiling::scope!("preload_text");
|
||||
|
||||
let style = TextStyle {
|
||||
font_stack: parley::FontStack::Single(parley::FontFamily::Generic(generic_family)),
|
||||
font_stack: FontStack::Single(font_family),
|
||||
font_weight: font_weight.unwrap_or(FontWeight::NORMAL),
|
||||
font_style,
|
||||
font_size,
|
||||
..Default::default()
|
||||
};
|
||||
@@ -194,13 +200,14 @@ impl Fonts {
|
||||
|
||||
let default_style = TextStyle::default();
|
||||
let style = TextStyle {
|
||||
font_stack: parley::FontStack::Single(parley::FontFamily::Generic(job.font_family)),
|
||||
font_stack: parley::FontStack::Single(job.font_family),
|
||||
font_size: job.font_size.into(),
|
||||
line_height: parley::LineHeight::Absolute(job.line_height.into()),
|
||||
font_weight: job
|
||||
.font_weight
|
||||
.map(|w| parley::FontWeight::new(w.into()))
|
||||
.unwrap_or(default_style.font_weight),
|
||||
font_style: job.font_style.into(),
|
||||
..default_style
|
||||
};
|
||||
|
||||
|
||||
+44
-5
@@ -1,37 +1,56 @@
|
||||
use crate::{color::Srgba, dpi::LogicalPoint, fonts::rasterizer::RasterizedGlyph};
|
||||
use ordered_float::OrderedFloat;
|
||||
use parley::GenericFamily;
|
||||
use parley::FontFamily;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Hash)]
|
||||
#[derive(Copy, Clone, Default, Debug, Hash, PartialEq)]
|
||||
pub enum Alignment {
|
||||
#[default]
|
||||
Min,
|
||||
Center,
|
||||
Max,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Default, Debug, Hash, PartialEq)]
|
||||
pub enum FontStyle {
|
||||
#[default]
|
||||
Normal,
|
||||
Italic,
|
||||
}
|
||||
|
||||
impl From<FontStyle> for parley::FontStyle {
|
||||
fn from(value: FontStyle) -> Self {
|
||||
match value {
|
||||
FontStyle::Normal => parley::FontStyle::Normal,
|
||||
FontStyle::Italic => parley::FontStyle::Italic,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Hash)]
|
||||
pub struct LayoutSegment<'s> {
|
||||
pub text: &'s str,
|
||||
pub color: Srgba,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Hash)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct LayoutJob<'s> {
|
||||
pub segments: Vec<LayoutSegment<'s>>,
|
||||
pub font_family: GenericFamily,
|
||||
pub font_family: FontFamily<'static>,
|
||||
pub font_size: OrderedFloat<f32>,
|
||||
pub line_height: OrderedFloat<f32>,
|
||||
pub alignment: Option<Alignment>,
|
||||
pub font_weight: Option<OrderedFloat<f32>>,
|
||||
pub font_style: FontStyle,
|
||||
}
|
||||
|
||||
impl<'s> LayoutJob<'s> {
|
||||
pub fn new(
|
||||
font_family: GenericFamily,
|
||||
font_family: FontFamily<'static>,
|
||||
font_size: f32,
|
||||
line_height: f32,
|
||||
alignment: Option<Alignment>,
|
||||
font_weight: Option<f32>,
|
||||
font_style: FontStyle,
|
||||
) -> Self {
|
||||
Self {
|
||||
segments: Vec::new(),
|
||||
@@ -40,6 +59,7 @@ impl<'s> LayoutJob<'s> {
|
||||
line_height: line_height.into(),
|
||||
alignment,
|
||||
font_weight: font_weight.map(OrderedFloat),
|
||||
font_style,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +68,25 @@ impl<'s> LayoutJob<'s> {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::hash::Hash for LayoutJob<'_> {
|
||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
self.segments.hash(state);
|
||||
match &self.font_family {
|
||||
FontFamily::Named(cow) => {
|
||||
cow.hash(state);
|
||||
}
|
||||
FontFamily::Generic(generic_family) => {
|
||||
generic_family.hash(state);
|
||||
}
|
||||
}
|
||||
self.font_size.hash(state);
|
||||
self.line_height.hash(state);
|
||||
self.alignment.hash(state);
|
||||
self.font_weight.hash(state);
|
||||
self.font_style.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct LayoutRow {
|
||||
pub glyphs: Vec<RasterizedGlyph>,
|
||||
|
||||
+23
-4
@@ -14,6 +14,7 @@ use image::GenericImage;
|
||||
use ordered_float::OrderedFloat;
|
||||
use parley::{FontData, GlyphRun};
|
||||
use std::borrow::Cow;
|
||||
use swash::zeno;
|
||||
|
||||
type FontBlobId = u64;
|
||||
type FontIndex = u32;
|
||||
@@ -25,14 +26,21 @@ struct StyleKey<'a> {
|
||||
font_blob_id: FontBlobId,
|
||||
font_size: OrderedFloat<f32>,
|
||||
normalized_coords: Cow<'a, [i16]>,
|
||||
skew: i8,
|
||||
}
|
||||
|
||||
impl<'a> StyleKey<'a> {
|
||||
fn new(font_blob_id: FontBlobId, font_size: f32, normalized_coords: &'a [i16]) -> Self {
|
||||
fn new(
|
||||
font_blob_id: FontBlobId,
|
||||
font_size: f32,
|
||||
normalized_coords: &'a [i16],
|
||||
skew: i8,
|
||||
) -> Self {
|
||||
Self {
|
||||
font_blob_id,
|
||||
font_size: font_size.into(),
|
||||
normalized_coords: Cow::Borrowed(normalized_coords),
|
||||
skew,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,8 +143,9 @@ impl GlyphRasterizer {
|
||||
font_data: &FontData,
|
||||
font_size: f32,
|
||||
norm_coords: &[i16],
|
||||
skew: i8,
|
||||
) -> StyleId {
|
||||
let style_key = StyleKey::new(font_data.data.id(), font_size, norm_coords);
|
||||
let style_key = StyleKey::new(font_data.data.id(), font_size, norm_coords, skew);
|
||||
match self.style_ids.get(&style_key) {
|
||||
Some(key) => *key,
|
||||
None => *self
|
||||
@@ -164,9 +173,16 @@ impl GlyphRasterizer {
|
||||
let color = glyph_run.style().brush;
|
||||
let font_size = run.font_size() * pixels_per_point;
|
||||
let normalized_coords = run.normalized_coords();
|
||||
let skew = run.synthesis().skew(); // skew angle for faux italic
|
||||
|
||||
let font_ref = self.get_font_ref(run.font());
|
||||
let style_id = self.get_style_id(run.font(), font_size, normalized_coords);
|
||||
let style_id = self.get_style_id(
|
||||
run.font(),
|
||||
font_size,
|
||||
normalized_coords,
|
||||
// parley stores skew as i8 internally so this conversion is ok
|
||||
skew.unwrap_or_default() as i8,
|
||||
);
|
||||
|
||||
let mut scaler = self
|
||||
.scale_context
|
||||
@@ -198,7 +214,10 @@ impl GlyphRasterizer {
|
||||
swash::scale::Source::ColorBitmap(swash::scale::StrikeWith::BestFit),
|
||||
swash::scale::Source::Outline,
|
||||
])
|
||||
.format(swash::zeno::Format::Alpha)
|
||||
.format(zeno::Format::Alpha)
|
||||
.transform(skew.map(|skew| {
|
||||
zeno::Transform::skew(zeno::Angle::from_degrees(skew), zeno::Angle::ZERO)
|
||||
}))
|
||||
.offset(fract_offset)
|
||||
.render_into(&mut scaler, glyph.id as u16, image);
|
||||
|
||||
|
||||
+1
-1
@@ -95,7 +95,7 @@ impl GraphicsContext {
|
||||
let surface_format = surface_caps
|
||||
.formats
|
||||
.iter()
|
||||
.find(|f| !f.is_srgb())
|
||||
.find(|f| !f.is_srgb() && f.required_features().is_empty())
|
||||
.copied()
|
||||
.unwrap_or(surface_caps.formats[0]);
|
||||
|
||||
|
||||
+120
-8
@@ -3,20 +3,23 @@ use crate::{
|
||||
args::Game,
|
||||
color::Srgba,
|
||||
dpi::{LogicalPoint, LogicalRect},
|
||||
fonts::{Alignment, LayoutJob},
|
||||
fonts::{Alignment, FontStyle, LayoutJob},
|
||||
mode::{AppEvent, ModeFrameOutput, ModeTransition},
|
||||
renderer::primitives::{ClippedPrimitive, DrawPrimitive, TextPrimitive},
|
||||
};
|
||||
use anyhow::bail;
|
||||
use flate2::read::GzDecoder;
|
||||
use parley::{FontFamily, GenericFamily};
|
||||
use regex::Regex;
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
use std::{
|
||||
fs::{self},
|
||||
io::{Write, copy},
|
||||
io::copy,
|
||||
path::{Path, PathBuf},
|
||||
sync::mpsc::{self, Receiver, TryRecvError},
|
||||
thread,
|
||||
};
|
||||
use ureq::http::Response;
|
||||
|
||||
const REPO_NAME: &str = "meehl/rusty-pob-manifest";
|
||||
|
||||
@@ -112,11 +115,12 @@ impl InstallMode {
|
||||
app_state: &mut AppState,
|
||||
) -> Box<dyn Iterator<Item = ClippedPrimitive>> {
|
||||
let mut job = LayoutJob::new(
|
||||
parley::GenericFamily::SansSerif,
|
||||
FontFamily::Generic(GenericFamily::SansSerif),
|
||||
32.0,
|
||||
34.0,
|
||||
Some(Alignment::Center),
|
||||
Some(700.0),
|
||||
FontStyle::Normal,
|
||||
);
|
||||
|
||||
let progress_text = match &self.current_progress {
|
||||
@@ -158,6 +162,14 @@ fn install<P: AsRef<Path>>(
|
||||
// Skip installation if version file exists
|
||||
let version_file_path = target_dir.as_ref().join("rpob.version");
|
||||
if version_file_path.exists() {
|
||||
let old_version = fs::read_to_string(&version_file_path).unwrap();
|
||||
let current_version = env!("CARGO_PKG_VERSION");
|
||||
|
||||
if old_version != current_version {
|
||||
log::info!("New version detected: {old_version} -> {current_version}");
|
||||
fs::write(&version_file_path, current_version).unwrap();
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -166,9 +178,7 @@ fn install<P: AsRef<Path>>(
|
||||
set_branch_and_platform(&target_dir)?;
|
||||
|
||||
// write version file
|
||||
let mut version_file = fs::File::create(version_file_path)?;
|
||||
let pkg_version = env!("CARGO_PKG_VERSION");
|
||||
version_file.write_all(pkg_version.as_bytes())?;
|
||||
fs::write(&version_file_path, env!("CARGO_PKG_VERSION")).unwrap();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -189,7 +199,7 @@ fn download_path_of_building<P: AsRef<Path>>(
|
||||
repo
|
||||
);
|
||||
|
||||
let mut response = ureq::get(url).call()?;
|
||||
let mut response = http_get_with_backoff(&url)?;
|
||||
let total_size = response
|
||||
.headers()
|
||||
.get("Content-Length")
|
||||
@@ -293,7 +303,7 @@ fn set_branch_and_platform<P: AsRef<Path>>(target_dir: P) -> anyhow::Result<()>
|
||||
}
|
||||
|
||||
fn download_file<P: AsRef<Path>>(url: &str, file_path: P) -> anyhow::Result<()> {
|
||||
let mut response = ureq::get(url).call()?;
|
||||
let mut response = http_get_with_backoff(url)?;
|
||||
|
||||
if response.status().is_success() {
|
||||
let body = response.body_mut();
|
||||
@@ -320,3 +330,105 @@ fn format_bytes(size_in_bytes: u64) -> String {
|
||||
format!("{} bytes", size_in_bytes)
|
||||
}
|
||||
}
|
||||
|
||||
/// Calculates wait time based on rate limit headers or falls back to default backoff.
|
||||
fn calculate_wait_time(resp: &Response<ureq::Body>, default_backoff: u64) -> u64 {
|
||||
let headers = resp.headers();
|
||||
|
||||
// Wait for time specified in retry-after response header if present
|
||||
if let Some(retry_after) = headers
|
||||
.get("retry-after")
|
||||
.and_then(|v| v.to_str().ok())
|
||||
.and_then(|s| s.parse::<u64>().ok())
|
||||
{
|
||||
return retry_after;
|
||||
}
|
||||
|
||||
// The number of requests remaining in the current rate limit window
|
||||
let remaining = headers
|
||||
.get("x-ratelimit-remaining")
|
||||
.and_then(|v| v.to_str().ok());
|
||||
|
||||
if remaining == Some("0") {
|
||||
// Calculate time until rate limit reset
|
||||
if let Some(reset_epoch) = headers
|
||||
.get("x-ratelimit-reset")
|
||||
.and_then(|v| v.to_str().ok())
|
||||
.and_then(|s| s.parse::<u64>().ok())
|
||||
{
|
||||
let now_epoch = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_secs();
|
||||
|
||||
if reset_epoch > now_epoch {
|
||||
return reset_epoch - now_epoch;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
default_backoff
|
||||
}
|
||||
|
||||
/// Performs a GET request with exponential backoff aware of GitHub rate limit headers.
|
||||
fn http_get_with_backoff(url: &str) -> anyhow::Result<Response<ureq::Body>> {
|
||||
const MAX_ATTEMPTS: usize = 6;
|
||||
const MAX_BACKOFF_SECS: u64 = 60;
|
||||
let mut attempt = 0;
|
||||
let mut backoff_secs: u64 = 2;
|
||||
|
||||
loop {
|
||||
attempt += 1;
|
||||
let resp_result = ureq::get(url)
|
||||
.header("User-Agent", "rusty-path-of-building")
|
||||
.call();
|
||||
|
||||
let resp = match resp_result {
|
||||
Ok(r) => r,
|
||||
Err(err) => {
|
||||
log::warn!(
|
||||
"Transport error: {} (attempt {}/{})",
|
||||
err,
|
||||
attempt,
|
||||
MAX_ATTEMPTS
|
||||
);
|
||||
if attempt >= MAX_ATTEMPTS {
|
||||
return Err(anyhow::Error::new(err));
|
||||
}
|
||||
thread::sleep(Duration::from_secs(backoff_secs));
|
||||
backoff_secs = (backoff_secs * 2).min(MAX_BACKOFF_SECS);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
let status = resp.status();
|
||||
if status == 403 || status == 429 {
|
||||
let wait = calculate_wait_time(&resp, backoff_secs);
|
||||
|
||||
log::warn!(
|
||||
"Rate limited (status {}). Waiting {}s before retry (attempt {}/{})",
|
||||
status,
|
||||
wait,
|
||||
attempt,
|
||||
MAX_ATTEMPTS
|
||||
);
|
||||
if attempt >= MAX_ATTEMPTS {
|
||||
return Err(anyhow::anyhow!(
|
||||
"HTTP {} after {} attempts for {}",
|
||||
status,
|
||||
attempt,
|
||||
url
|
||||
));
|
||||
}
|
||||
thread::sleep(Duration::from_secs(wait));
|
||||
backoff_secs = (backoff_secs * 2).min(MAX_BACKOFF_SECS);
|
||||
continue;
|
||||
}
|
||||
|
||||
if status.is_client_error() || status.is_server_error() {
|
||||
return Err(anyhow::anyhow!("http status: {} for {}", status, url));
|
||||
}
|
||||
|
||||
return Ok(resp);
|
||||
}
|
||||
}
|
||||
@@ -121,9 +121,13 @@ impl PoBMode {
|
||||
}
|
||||
AppEvent::MouseWheel { delta } => {
|
||||
if delta > 0.0 {
|
||||
self.lua_instance
|
||||
.handle_event(PoBEvent::KeyDown("WHEELUP", false), &mut ctx)?;
|
||||
self.lua_instance
|
||||
.handle_event(PoBEvent::KeyUp("WHEELUP"), &mut ctx)?;
|
||||
} else if delta < 0.0 {
|
||||
self.lua_instance
|
||||
.handle_event(PoBEvent::KeyDown("WHEELDOWN", false), &mut ctx)?;
|
||||
self.lua_instance
|
||||
.handle_event(PoBEvent::KeyUp("WHEELDOWN"), &mut ctx)?;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user