33namespace App \Badges \Components ;
44
55use Imagine \Gd \Font ;
6- use Imagine \Image \Box ;
76use Imagine \Image \ImageInterface ;
87use Imagine \Image \Palette \Color \ColorInterface ;
98use Imagine \Image \Palette \RGB ;
1615 */
1716class TextField
1817{
19- private string $ text ; // Der Text, der in das Bild gezeichnet werden soll
18+ private string $ text ; // The text to be drawn in the image
2019
21- private int $ width ; // Die Breite des Bereichs, in den der Text gezeichnet wird
20+ private int $ width ; // The width of the area in which the text is drawn
2221
23- private int $ height ; // Die Höhe des Bereichs, in den der Text gezeichnet wird
22+ private int $ height ; // The height of the area in which the text is drawn
2423
25- private int $ minFontSize ; // Die minimale Schriftgröße, die verwendet werden darf
24+ private int $ minFontSize ; // The minimum font size that may be used
2625
27- private int $ startFontSize ; // Die anfängliche Schriftgröße, die verwendet wird
26+ private int $ startFontSize ; // The initial font size that will be used
2827
29- private string $ font_path ; // Der Pfad zur Schriftartdatei
28+ private string $ font_path ; // The path to the font file
3029
31- private ColorInterface $ font_color ; // Die Farbe des Textes
30+ private ColorInterface $ font_color ; // The color of the text
3231
33- private string $ alignment ; // Die Ausrichtung des Textes (links, zentriert, rechts )
32+ private string $ alignment ; // The alignment of the text (left, centered, right )
3433
35- private int $ maxRows ; // Die maximale Anzahl der Zeilen, die der Text haben darf
34+ private int $ maxRows ; // The maximum number of lines the text may have
3635
37- private ?ColorInterface $ backgroundColor ; // Hintergrundfarbe der Textbox
36+ private ?ColorInterface $ backgroundColor ; // Background color of the text box
3837
39- private ?ColorInterface $ borderColor ; // Farbe des Rahmens
38+ private ?ColorInterface $ borderColor ; // Color of the frame
4039
41- private int $ borderThickness ; // Dicke des Rahmens
40+ private int $ borderThickness ; // Thickness of the frame
4241
43- private int $ borderRadius ; // Radius der abgerundeten Ecken
42+ private int $ borderRadius ; // Radius of the rounded corners
4443
45- private ?ColorInterface $ textStrokeColor ; // Farbe der Textumrahmung
44+ private ?ColorInterface $ textStrokeColor ; // Color of the text frame
4645
47- private int $ textStrokeThickness ; // Dicke der Textumrahmung
46+ private int $ textStrokeThickness ; // Thickness of the text frame
4847
4948 /**
5049 * Constructor for the TextField class.
@@ -79,12 +78,12 @@ public function __construct(
7978 PointInterface $ position ,
8079 string $ alignment , // Standardmäßig linksbündig
8180 int $ maxRows ,
82- ?ColorInterface $ backgroundColor = null , // Standardmäßig kein Hintergrund
83- ?ColorInterface $ borderColor = null , // Standardmäßig keine Umrandung
84- int $ borderThickness = 0 , // Standardmäßig keine Umrandung
85- int $ borderRadius = 0 , // Standardmäßig keine abgerundeten Ecken
86- ?ColorInterface $ textStrokeColor = null , // Standardmäßig keine Textumrahmung
87- float $ textStrokeThickness = 0 // Standardmäßig keine Textumrahmung
81+ ?ColorInterface $ backgroundColor = null , // No background by default
82+ ?ColorInterface $ borderColor = null , // No border by default
83+ int $ borderThickness = 0 , // No border by default
84+ int $ borderRadius = 0 , // No rounded corners by default
85+ ?ColorInterface $ textStrokeColor = null , // No text border by default
86+ float $ textStrokeThickness = 0 // No text border by default
8887 ) {
8988 $ this ->text = $ text ;
9089 $ this ->width = $ width ;
@@ -102,7 +101,7 @@ public function __construct(
102101 $ this ->textStrokeColor = $ textStrokeColor ;
103102 $ this ->textStrokeThickness = $ textStrokeThickness ;
104103
105- // Zeichne den Text beim Erstellen des Objekts
104+ // Draw the text when creating the object
106105 return $ this ->drawTextInBox ($ image , $ position );
107106 }
108107
@@ -116,28 +115,28 @@ public function __construct(
116115 */
117116 protected function drawTextInBox (ImageInterface $ image , PointInterface $ position ): ImageInterface
118117 {
119- $ fontSize = $ this ->startFontSize ; // Startet mit der anfänglichen Schriftgröße
120- $ palette = new RGB ; // Erzeuge eine RGB-Palette
118+ $ fontSize = $ this ->startFontSize ; // Starts with the initial font size
119+ $ palette = new RGB ; // Create an RGB palette
121120
122121 do {
123- // Berechne die Box-Größe mit der aktuellen Schriftgröße
122+ // Calculate the box size with the current font size
124123 $ font = new Font ($ this ->font_path , $ fontSize , $ this ->font_color );
125124 $ textBox = $ font ->box ($ this ->text );
126125
127- // Überprüft, ob der Text in die Box passt
126+ // Checks whether the text fits into the box
128127 if ($ textBox ->getWidth () > $ this ->width || $ textBox ->getHeight () > $ this ->height ) {
129- $ fontSize --; // Reduziert die Schriftgröße, wenn der Text zu groß ist
128+ $ fontSize --; // Reduces the font size if the text is too large
130129 } else {
131- break ; // Passt, keine weiteren Änderungen erforderlich
130+ break ; // Fits, no further changes required
132131 }
133132 } while ($ fontSize >= $ this ->minFontSize );
134133
135- // Berechne die vertikale Position, um den Text zentriert zu platzieren
134+ // Calculate the vertical position to center the text
136135 $ y = $ position ->getY () + ($ this ->height - $ textBox ->getHeight ()) / 2 ;
137- // Berechne die horizontale Position basierend auf der Ausrichtung (zentriert, links oder rechts )
136+ // Calculate the horizontal position based on the orientation (centered, left or right )
138137 $ x = $ this ->calculateXPosition ($ textBox ->getWidth (), $ position );
139138
140- // Zeichnet den Textumriss, falls angegeben
139+ // Draws the text outline, if specified
141140 if ($ this ->textStrokeColor && $ this ->textStrokeThickness > 0 ) {
142141 for ($ offsetX = -$ this ->textStrokeThickness ; $ offsetX <= $ this ->textStrokeThickness ; $ offsetX ++) {
143142 for ($ offsetY = -$ this ->textStrokeThickness ; $ offsetY <= $ this ->textStrokeThickness ; $ offsetY ++) {
@@ -152,14 +151,14 @@ protected function drawTextInBox(ImageInterface $image, PointInterface $position
152151 }
153152 }
154153
155- // Zeichnet den Text auf das Bild an der berechneten Position
154+ // Draws the text on the image at the calculated position
156155 $ image ->draw ()->text ($ this ->text , $ font , new Point ($ x , $ y ));
157156
158157 return $ image ;
159158 }
160159
161160 /**
162- * Berechnet die X-Position des Textes basierend auf der Ausrichtung .
161+ * Calculates the X-position of the text based on the alignment .
163162 */
164163 private function calculateXPosition (int $ textWidth , PointInterface $ position ): int
165164 {
@@ -170,7 +169,7 @@ private function calculateXPosition(int $textWidth, PointInterface $position): i
170169 return $ position ->getX () + ($ this ->width - $ textWidth );
171170 case TextAlignment::LEFT :
172171 default :
173- return $ position ->getX (); // Linksbündig
172+ return $ position ->getX (); // Left-aligned
174173 }
175174 }
176175}
0 commit comments