forked from 1b-agent/opencadstudio-upstream
fix(pdfshxtext): reference grouping, object share, wider glyph set, drawing-order import
Text blocks join side by side or stacked within two heights; oversized shapes join no group; the group share counts selected objects; Latin-1, Latin Extended, Greek, Cyrillic and the diameter sign are compared from the font's own glyphs with look-alikes resolved to the lowest code; a lone circle reads 0; MTEXT direction is by style. PDFIMPORT keeps drawing order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
218150c76a
commit
2eb60f333f
4 files changed
+134
-48
No files matched your search
@@ -783,6 +783,8 @@ pub const DASH_LINETYPE: &str = "PDF_IMPORT";
|
||||
/// as dashes. `bulges[i]` bends the segment from point i to the next (the
|
||||
/// closing one on a closed stroke; 0 after an open stroke's last point).
|
||||
struct Stroke {
|
||||
/// Drawing position: the objects are created in drawing order.
|
||||
order: usize,
|
||||
layer: String,
|
||||
color: Color,
|
||||
weight: LineWeight,
|
||||
@@ -1205,6 +1207,8 @@ fn join_strokes(strokes: Vec<Stroke>, join: bool) -> Vec<Stroke> {
|
||||
}
|
||||
out.push(chain);
|
||||
}
|
||||
// A chain takes the place of its first stroke.
|
||||
out.sort_by_key(|s| s.order);
|
||||
out
|
||||
}
|
||||
|
||||
@@ -1212,6 +1216,7 @@ fn join_strokes(strokes: Vec<Stroke>, join: bool) -> Vec<Stroke> {
|
||||
fn split_at_arcs(stroke: Stroke) -> Vec<Stroke> {
|
||||
let mut out = Vec::new();
|
||||
let piece = |points: Vec<[f64; 2]>, bulges: Vec<f64>| Stroke {
|
||||
order: stroke.order,
|
||||
layer: stroke.layer.clone(),
|
||||
color: stroke.color,
|
||||
weight: stroke.weight,
|
||||
@@ -1364,7 +1369,8 @@ pub fn convert(
|
||||
};
|
||||
let fill_transparency = codec::types::Transparency::from_alpha_value(0x0200_007F);
|
||||
let mut strokes: Vec<Stroke> = Vec::new();
|
||||
let mut curves: Vec<EntityType> = Vec::new();
|
||||
// Circles and splines, by drawing position like the strokes.
|
||||
let mut curves: Vec<(usize, EntityType)> = Vec::new();
|
||||
|
||||
for (pdf_layer, page) in content {
|
||||
let pdf_layer = pdf_layer.as_deref();
|
||||
@@ -1383,6 +1389,7 @@ pub fn convert(
|
||||
LineWeight::ByLayer
|
||||
};
|
||||
for sp in &path.subpaths {
|
||||
let order = strokes.len() + curves.len();
|
||||
if let Some((c, r)) = as_circle(sp) {
|
||||
let w = world(c);
|
||||
let mut circle = EntityType::Circle(Circle::from_center_radius(
|
||||
@@ -1392,7 +1399,7 @@ pub fn convert(
|
||||
let common = circle.common_mut();
|
||||
(common.layer, common.color, common.line_weight) =
|
||||
(layer.clone(), color, weight);
|
||||
curves.push(circle);
|
||||
curves.push((order, circle));
|
||||
} else {
|
||||
// Straight and circular runs become polylines;
|
||||
// each other curve its own one-span SPLINE.
|
||||
@@ -1401,6 +1408,7 @@ pub fn convert(
|
||||
match piece {
|
||||
Piece::Run(points, bulges, closed) => {
|
||||
let stroke = Stroke {
|
||||
order,
|
||||
layer: layer.clone(),
|
||||
color,
|
||||
weight,
|
||||
@@ -1427,7 +1435,7 @@ pub fn convert(
|
||||
let common = spline.common_mut();
|
||||
(common.layer, common.color, common.line_weight) =
|
||||
(layer.clone(), color, weight);
|
||||
curves.push(spline);
|
||||
curves.push((order, spline));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1542,7 +1550,7 @@ pub fn convert(
|
||||
let common = curve.common_mut();
|
||||
(common.layer, common.color, common.line_weight) =
|
||||
(stroke.layer, stroke.color, stroke.weight);
|
||||
result.entities.push(curve);
|
||||
curves.push((stroke.order, curve));
|
||||
None
|
||||
}
|
||||
None => Some(stroke),
|
||||
@@ -1576,7 +1584,7 @@ pub fn convert(
|
||||
);
|
||||
(arc.common.layer, arc.common.color, arc.common.line_weight) =
|
||||
(stroke.layer, stroke.color, stroke.weight);
|
||||
result.entities.push(EntityType::Arc(arc));
|
||||
curves.push((stroke.order, EntityType::Arc(arc)));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -1593,9 +1601,11 @@ pub fn convert(
|
||||
pl.common.linetype_scale = dash * scale;
|
||||
result.dashed = true;
|
||||
}
|
||||
result.entities.push(EntityType::LwPolyline(pl));
|
||||
curves.push((stroke.order, EntityType::LwPolyline(pl)));
|
||||
}
|
||||
result.entities.extend(curves);
|
||||
// In drawing order (the sort is stable: a subpath's pieces keep theirs).
|
||||
curves.sort_by_key(|(order, _)| *order);
|
||||
result.entities.extend(curves.into_iter().map(|(_, entity)| entity));
|
||||
result.layers = layer_colors;
|
||||
for image in &result.images {
|
||||
if !result.layers.iter().any(|(n, _)| *n == image.layer) {
|
||||
|
||||
Reference in new issue
Block a user