@@ -26,53 +26,51 @@ public static SKImage Label_ITF14(Barcode barcode, SKBitmap img)
2626 var labelPadding = textBounds . Height / 2f ;
2727 var backY = img . Height - textBounds . Height - labelPadding * 2f ;
2828
29- using ( var canvas = new SKCanvas ( img ) )
29+ using var canvas = new SKCanvas ( img ) ;
30+ //draw bounding box side overdrawn by label
31+ using ( var pen = new SKPaint ( ) )
3032 {
31- //draw bounding box side overdrawn by label
32- using ( var pen = new SKPaint ( ) )
33- {
34- pen . FilterQuality = SKFilterQuality . High ;
35- pen . IsAntialias = true ;
36- pen . ColorF = barcode . ForeColor ;
37- pen . StrokeWidth = ( float ) img . Height / 16 ;
38-
39- canvas . DrawLine ( new SKPoint ( 0 , backY - pen . StrokeWidth / 2f ) ,
40- new SKPoint ( img . Width , backY - pen . StrokeWidth / 2f ) , pen ) ; //bottom
41- }
42-
43- //color a box at the bottom of the barcode to hold the string of data
44- using ( var paint = new SKPaint ( font ) )
45- {
46- paint . FilterQuality = SKFilterQuality . High ;
47- paint . IsAntialias = true ;
48- paint . ColorF = barcode . BackColor ;
49- paint . Style = SKPaintStyle . Fill ;
50-
51- var rect = SKRect . Create ( 0 , backY , img . Width , textBounds . Height + labelPadding * 2f ) ;
52- canvas . DrawRect ( rect , paint ) ;
53- }
54-
55- //draw datastring under the barcode image
56- foreBrush . FilterQuality = SKFilterQuality . High ;
57- foreBrush . IsAntialias = true ;
58- foreBrush . ColorF = barcode . ForeColor ;
59- foreBrush . TextAlign = SKTextAlign . Center ;
60-
61- var labelX = img . Width / 2f ;
62- var labelY = img . Height - textBounds . Height + labelPadding ;
63-
64- canvas . DrawText ( str , labelX , labelY , foreBrush ) ;
65-
66- canvas . Save ( ) ;
67- } //using
33+ pen . FilterQuality = SKFilterQuality . High ;
34+ pen . IsAntialias = true ;
35+ pen . ColorF = barcode . ForeColor ;
36+ pen . StrokeWidth = ( float ) img . Height / 16 ;
37+
38+ canvas . DrawLine ( new SKPoint ( 0 , backY - pen . StrokeWidth / 2f ) ,
39+ new SKPoint ( img . Width , backY - pen . StrokeWidth / 2f ) , pen ) ; //bottom
40+ }
41+
42+ //color a box at the bottom of the barcode to hold the string of data
43+ using ( var paint = new SKPaint ( font ) )
44+ {
45+ paint . FilterQuality = SKFilterQuality . High ;
46+ paint . IsAntialias = true ;
47+ paint . ColorF = barcode . BackColor ;
48+ paint . Style = SKPaintStyle . Fill ;
49+
50+ var rect = SKRect . Create ( 0 , backY , img . Width , textBounds . Height + labelPadding * 2f ) ;
51+ canvas . DrawRect ( rect , paint ) ;
52+ }
53+
54+ //draw datastring under the barcode image
55+ foreBrush . FilterQuality = SKFilterQuality . High ;
56+ foreBrush . IsAntialias = true ;
57+ foreBrush . ColorF = barcode . ForeColor ;
58+ foreBrush . TextAlign = SKTextAlign . Center ;
59+
60+ var labelX = img . Width / 2f ;
61+ var labelY = img . Height - textBounds . Height + labelPadding ;
62+
63+ canvas . DrawText ( str , labelX , labelY , foreBrush ) ;
64+
65+ canvas . Save ( ) ;
6866 }
6967
7068 return SKImage . FromBitmap ( img ) ;
71- } //try
69+ }
7270 catch ( Exception ex )
7371 {
7472 throw new Exception ( "ELABEL_ITF14-1: " + ex . Message ) ;
75- } //catch
73+ }
7674 }
7775
7876 /// <summary>
@@ -128,11 +126,11 @@ public static SKImage Label_Generic(Barcode barcode, SKBitmap img)
128126 g . Save ( ) ;
129127 }
130128 return SKImage . FromBitmap ( img ) ;
131- } //try
129+ }
132130 catch ( Exception ex )
133131 {
134132 throw new Exception ( "ELABEL_GENERIC-1: " + ex . Message ) ;
135- } //catch
133+ }
136134 finally
137135 {
138136 foreBrush . Dispose ( ) ;
@@ -220,11 +218,11 @@ public static SKImage Label_EAN13(Barcode barcode, SKBitmap img)
220218 }
221219
222220 return SKImage . FromBitmap ( img ) ;
223- } //try
221+ }
224222 catch ( Exception ex )
225223 {
226224 throw new Exception ( "ELABEL_EAN13-1: " + ex . Message ) ;
227- } //catch
225+ }
228226 finally
229227 {
230228 foreBrush . Dispose ( ) ;
@@ -316,19 +314,19 @@ public static SKImage Label_UPCA(Barcode barcode, SKBitmap img)
316314 }
317315
318316 return SKImage . FromBitmap ( img ) ;
319- } //try
317+ }
320318 catch ( Exception ex )
321319 {
322320 throw new Exception ( "ELABEL_UPCA-1: " + ex . Message ) ;
323- } //catch
321+ }
324322 finally
325323 {
326324 foreBrush . Dispose ( ) ;
327325 backBrush . Dispose ( ) ;
328326 }
329327 } //Label_UPCA
330328
331- private static int GetFontSize ( Barcode barcode , int wid , int hgt , string lbl )
329+ /* private static int GetFontSize(int wid, int hgt, string lbl)
332330 {
333331 //Returns the optimal font size for the specified dimensions
334332 var fontSize = 10;
@@ -338,23 +336,19 @@ private static int GetFontSize(Barcode barcode, int wid, int hgt, string lbl)
338336 var bounds = SKRect.Empty;
339337 for (var i = 1; i <= 100; i++)
340338 {
341- using ( var testFont = new SKFont ( SKTypeface . FromFamilyName ( "Arial" , SKFontStyle . Normal ) , i ) )
342- {
343- // Make a Graphics object to measure the text.
344- using ( var gr = new SKPaint ( testFont ) )
345- {
346- gr . MeasureText ( lbl , ref bounds ) ;
347-
348- if ( ! ( bounds . Width > wid ) && ! ( bounds . Height > hgt ) ) continue ;
349- fontSize = i - 1 ;
350- break ;
351- }
352- }
339+ using var testFont = new SKFont(SKTypeface.FromFamilyName("Arial", SKFontStyle.Normal), i);
340+ // Make a Graphics object to measure the text.
341+ using var gr = new SKPaint(testFont);
342+ gr.MeasureText(lbl, ref bounds);
343+
344+ if (!(bounds.Width > wid) && !(bounds.Height > hgt)) continue;
345+ fontSize = i - 1;
346+ break;
353347 }
354348
355349 };
356350
357351 return fontSize;
358- }
352+ }*/
359353 }
360354}
0 commit comments