[glabels/vala] Better parameterization of base font parameters.
- From: Jim Evins <jimevins src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glabels/vala] Better parameterization of base font parameters.
- Date: Fri, 14 Sep 2012 01:00:48 +0000 (UTC)
commit 0340622849c3a5177b0406a1c674598d53dbf2d9
Author: Jim Evins <evins snaught com>
Date: Thu Sep 13 21:00:11 2012 -0400
Better parameterization of base font parameters.
libglbarcode/barcode_code39.vala | 16 +++++++++-------
libglbarcode/barcode_upc.vala | 27 ++++++++++++++-------------
libglbarcode/constants.vala | 2 ++
3 files changed, 25 insertions(+), 20 deletions(-)
---
diff --git a/libglbarcode/barcode_code39.vala b/libglbarcode/barcode_code39.vala
index 9b027c2..ec6fc98 100644
--- a/libglbarcode/barcode_code39.vala
+++ b/libglbarcode/barcode_code39.vala
@@ -34,10 +34,8 @@ namespace glbarcode
private const double MIN_HEIGHT = ( 0.25 * PTS_PER_INCH );
private const double MIN_QUIET = ( 0.10 * PTS_PER_INCH );
- private const double INK_BLEED = ( 0.00325 * PTS_PER_INCH );
-
- private const double TEXT_AREA_HEIGHT = 14.0;
- private const double TEXT_SIZE = 10.0;
+ private const double MIN_TEXT_AREA_HEIGHT = 14.0;
+ private const double MIN_TEXT_SIZE = 10.0;
/* Code 39 alphabet. Position indicates value. */
@@ -174,8 +172,12 @@ namespace glbarcode
}
double width = min_l * scale;
+ /* determine text parameters */
+ double h_text_area = scale * MIN_TEXT_AREA_HEIGHT;
+ double text_size = scale * MIN_TEXT_SIZE;
+
/* determine height of barcode */
- double height = text_flag ? h - TEXT_AREA_HEIGHT : h;
+ double height = text_flag ? h - h_text_area : h;
height = double.max( height, double.max( 0.15*width, MIN_HEIGHT ) );
/* determine horizontal quiet zone */
@@ -224,11 +226,11 @@ namespace glbarcode
if ( text_flag )
{
string starred_text = "*%s*".printf( text );
- add_string( x_quiet + width/2, height + (TEXT_AREA_HEIGHT-TEXT_SIZE)/2, TEXT_SIZE, starred_text );
+ add_string( x_quiet + width/2, height + (h_text_area-text_size)/2, text_size, starred_text );
}
this.w = width + 2*x_quiet;
- this.h = text_flag ? height + TEXT_AREA_HEIGHT : height;
+ this.h = text_flag ? height + h_text_area : height;
}
diff --git a/libglbarcode/barcode_upc.vala b/libglbarcode/barcode_upc.vala
index 30e5507..8594164 100644
--- a/libglbarcode/barcode_upc.vala
+++ b/libglbarcode/barcode_upc.vala
@@ -28,10 +28,11 @@ namespace glbarcode
public class BarcodeUPCA : Barcode
{
- private const double MODULE0 = ( 0.01 * PTS_PER_INCH );
private const int QUIET_MODULES = 9;
- private const double INK_BLEED = ( 0.00325 * PTS_PER_INCH );
+ private const double BASE_MODULE_SIZE = ( 0.01 * PTS_PER_INCH );
+ private const double BASE_FONT_SIZE = 7.2;
+ private const double BASE_TEXT_AREA_HEIGHT = 11;
private const string[] symbols = {
@@ -176,28 +177,28 @@ namespace glbarcode
}
else
{
- scale = w / ((n_modules + 2*QUIET_MODULES) * MODULE0);
+ scale = w / ((n_modules + 2*QUIET_MODULES) * BASE_MODULE_SIZE);
if ( scale < 1.0 )
{
scale = 1.0;
}
}
- double width = (n_modules + 2*QUIET_MODULES) * scale * MODULE0;
+ double width = (n_modules + 2*QUIET_MODULES) * scale * BASE_MODULE_SIZE;
/* determine text parameters */
- double h_text_area = 14 * scale * MODULE0;
- double text_size1 = 10 * scale * MODULE0;
- double text_size2 = 0.75*text_size1;
- double text_c1 = (QUIET_MODULES + 5 + n_modules/4) * scale * MODULE0;
- double text_c2 = (QUIET_MODULES - 4 + 3*n_modules/4) * scale * MODULE0;
+ double h_text_area = scale * BASE_TEXT_AREA_HEIGHT;
+ double text_size1 = scale * BASE_FONT_SIZE;
+ double text_size2 = 0.75*text_size1;
+ double text_c1 = (QUIET_MODULES + 5 + n_modules/4) * scale * BASE_MODULE_SIZE;
+ double text_c2 = (QUIET_MODULES - 4 + 3*n_modules/4) * scale * BASE_MODULE_SIZE;
/* determine bar height */
double h_bar1 = double.max( (h - h_text_area), width/2 );
double h_bar2 = h_bar1 + h_text_area/2;
/* determine horizontal quiet zone */
- double x_quiet = QUIET_MODULES * scale * MODULE0;
+ double x_quiet = QUIET_MODULES * scale * BASE_MODULE_SIZE;
/* now traverse the code string and draw each bar */
double x1 = x_quiet;
@@ -218,13 +219,13 @@ namespace glbarcode
/* Bar */
int bar_w = coded_data[i].digit_value();
- add_box( x1, 0.0, (bar_w*scale*MODULE0 - INK_BLEED), h_bar );
- x1 += bar_w * scale * MODULE0;
+ add_box( x1, 0.0, (bar_w*scale*BASE_MODULE_SIZE - INK_BLEED), h_bar );
+ x1 += bar_w * scale * BASE_MODULE_SIZE;
/* Space */
int space_w = coded_data[i+1].digit_value();
- x1 += space_w * scale * MODULE0;
+ x1 += space_w * scale * BASE_MODULE_SIZE;
}
/* draw text */
diff --git a/libglbarcode/constants.vala b/libglbarcode/constants.vala
index 0b94759..2ac19a6 100644
--- a/libglbarcode/constants.vala
+++ b/libglbarcode/constants.vala
@@ -31,6 +31,8 @@ namespace glbarcode
public const double PTS_PER_MM = 2.83464566929;
public const double PTS_PER_CM = 10*PTS_PER_MM;
+ public const double INK_BLEED = ( 0.00325 * PTS_PER_INCH );
+
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]