Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -914,17 +914,28 @@ def predict(
|
|
| 914 |
|
| 915 |
if annotation_text.strip():
|
| 916 |
if boundary_polygon is not None:
|
| 917 |
-
|
| 918 |
-
text_height_dxf = 0.75
|
| 919 |
text_y_dxf = boundary_polygon.bounds[1] + 0.25
|
| 920 |
font = get_font_face("Arial")
|
|
|
|
|
|
|
| 921 |
paths = text2path.make_paths_from_str(
|
| 922 |
annotation_text.strip().upper(),
|
| 923 |
-
font=font,
|
| 924 |
size=text_height_dxf,
|
| 925 |
align=TextEntityAlignment.LEFT
|
| 926 |
)
|
| 927 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 928 |
# Create a translation matrix
|
| 929 |
translation = ezdxf.math.Matrix44.translate(text_x, text_y_dxf, 0)
|
| 930 |
# Apply the translation to each path
|
|
|
|
| 914 |
|
| 915 |
if annotation_text.strip():
|
| 916 |
if boundary_polygon is not None:
|
| 917 |
+
text_height_dxf = 0.75
|
|
|
|
| 918 |
text_y_dxf = boundary_polygon.bounds[1] + 0.25
|
| 919 |
font = get_font_face("Arial")
|
| 920 |
+
|
| 921 |
+
# Create text paths first
|
| 922 |
paths = text2path.make_paths_from_str(
|
| 923 |
annotation_text.strip().upper(),
|
| 924 |
+
font=font,
|
| 925 |
size=text_height_dxf,
|
| 926 |
align=TextEntityAlignment.LEFT
|
| 927 |
)
|
| 928 |
|
| 929 |
+
# Calculate actual text width from the path's bounds
|
| 930 |
+
text_bbox = path.bbox(paths)
|
| 931 |
+
text_width = text_bbox[2] - text_bbox[0] # xmax - xmin
|
| 932 |
+
|
| 933 |
+
# Calculate center point of inner tool contours
|
| 934 |
+
center_x = (inner_min_x + inner_max_x) / 2.0
|
| 935 |
+
|
| 936 |
+
# Calculate starting x position for truly centered text
|
| 937 |
+
text_x = center_x - (text_width / 2.0)
|
| 938 |
+
|
| 939 |
# Create a translation matrix
|
| 940 |
translation = ezdxf.math.Matrix44.translate(text_x, text_y_dxf, 0)
|
| 941 |
# Apply the translation to each path
|