Skip to content

Introduce text alignment #2704

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use graph_craft::document::*;
use graphene_core::raster::brush_cache::BrushCache;
use graphene_core::raster::image::RasterDataTable;
use graphene_core::raster::{CellularDistanceFunction, CellularReturnType, Color, DomainWarpType, FractalType, NoiseType, RedGreenBlueAlpha};
use graphene_core::text::{Font, TypesettingConfig};
use graphene_core::text::{Font, TextAlignment, TypesettingConfig};
use graphene_core::transform::Footprint;
use graphene_core::vector::VectorDataTable;
use graphene_core::*;
Expand Down Expand Up @@ -1987,6 +1987,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
NodeInput::value(TaggedValue::F64(TypesettingConfig::default().character_spacing), false),
NodeInput::value(TaggedValue::OptionalF64(TypesettingConfig::default().max_width), false),
NodeInput::value(TaggedValue::OptionalF64(TypesettingConfig::default().max_height), false),
NodeInput::value(TaggedValue::TextAlignment(TypesettingConfig::default().text_alignment), false),
],
..Default::default()
},
Expand Down Expand Up @@ -2040,6 +2041,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
..Default::default()
}),
),
PropertiesRow::with_override("Text Alignment", "TODO", WidgetOverride::Custom("text_alignment".to_string())),
],
output_names: vec!["Vector".to_string()],
..Default::default()
Expand Down Expand Up @@ -3311,6 +3313,16 @@ fn static_input_properties() -> InputProperties {
)])
}),
);
map.insert(
"text_alignment".to_string(),
Box::new(|node_id, index, context| {
let (document_node, input_name, input_description) = node_properties::query_node_and_input_info(node_id, index, context)?;
let text_alignment = enum_choice::<TextAlignment>()
.for_socket(ParameterWidgetsInfo::new(document_node, node_id, index, input_name, input_description, true))
.property_row();
Ok(vec![text_alignment])
}),
);
map
}

Expand Down
7 changes: 6 additions & 1 deletion editor/src/messages/portfolio/portfolio_message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMes
}

// Upgrade Text node to include line height and character spacing, which were previously hardcoded to 1, from https://github.com/GraphiteEditor/Graphite/pull/2016
if reference == "Text" && inputs_count != 8 {
if reference == "Text" && inputs_count != 9 {
let node_definition = resolve_document_node_type(reference).unwrap();
let document_node = node_definition.default_node_template().document_node;
document.network_interface.replace_implementation(node_id, network_path, document_node.implementation.clone());
Expand Down Expand Up @@ -789,6 +789,11 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMes
NodeInput::value(TaggedValue::OptionalF64(TypesettingConfig::default().max_height), false),
network_path,
);
document.network_interface.set_input(
&InputConnector::node(*node_id, 8),
NodeInput::value(TaggedValue::TextAlignment(TypesettingConfig::default().text_alignment), false),
network_path,
);
}

// Upgrade Sine, Cosine, and Tangent nodes to include a boolean input for whether the output should be in radians, which was previously the only option but is now not the default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,15 @@ pub fn get_text(layer: LayerNodeIdentifier, network_interface: &NodeNetworkInter
let Some(&TaggedValue::F64(character_spacing)) = inputs[5].as_value() else { return None };
let Some(&TaggedValue::OptionalF64(max_width)) = inputs[6].as_value() else { return None };
let Some(&TaggedValue::OptionalF64(max_height)) = inputs[7].as_value() else { return None };
let Some(&TaggedValue::TextAlignment(text_alignment)) = inputs[8].as_value() else { return None };

let typesetting = TypesettingConfig {
font_size,
line_height_ratio,
max_width,
character_spacing,
max_height,
text_alignment,
};
Some((text, font, typesetting))
}
Expand Down
3 changes: 2 additions & 1 deletion editor/src/messages/tool/tool_messages/text_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use graph_craft::document::value::TaggedValue;
use graph_craft::document::{NodeId, NodeInput};
use graphene_core::Color;
use graphene_core::renderer::Quad;
use graphene_core::text::{Font, FontCache, TypesettingConfig, lines_clipping, load_face};
use graphene_core::text::{Font, FontCache, TextAlignment, TypesettingConfig, lines_clipping, load_face};
use graphene_core::vector::style::Fill;

#[derive(Default)]
Expand Down Expand Up @@ -784,6 +784,7 @@ impl Fsm for TextToolFsmState {
max_width: constraint_size.map(|size| size.x),
character_spacing: tool_options.character_spacing,
max_height: constraint_size.map(|size| size.y),
text_alignment: TextAlignment::default(),
},
font: Font::new(tool_options.font_name.clone(), tool_options.font_style.clone()),
color: tool_options.fill.active_color(),
Expand Down
Binary file added node-graph/gcore/src/text/TestBoxFont.ttf
Binary file not shown.
Loading