...

Source file src/github.com/boombuler/barcode/pdf417/dimensions.go

Documentation: github.com/boombuler/barcode/pdf417

     1  package pdf417
     2  
     3  import "math"
     4  
     5  const (
     6  	minCols         = 2
     7  	maxCols         = 30
     8  	maxRows         = 30
     9  	minRows         = 2
    10  	moduleHeight    = 2
    11  	preferred_ratio = 3.0
    12  )
    13  
    14  func calculateNumberOfRows(m, k, c int) int {
    15  	r := ((m + 1 + k) / c) + 1
    16  	if c*r >= (m + 1 + k + c) {
    17  		r--
    18  	}
    19  	return r
    20  }
    21  
    22  func calcDimensions(dataWords, eccWords int) (cols, rows int) {
    23  	ratio := 0.0
    24  	cols = 0
    25  	rows = 0
    26  
    27  	for c := minCols; c <= maxCols; c++ {
    28  		r := calculateNumberOfRows(dataWords, eccWords, c)
    29  
    30  		if r < minRows {
    31  			break
    32  		}
    33  
    34  		if r > maxRows {
    35  			continue
    36  		}
    37  
    38  		newRatio := float64(17*cols+69) / float64(rows*moduleHeight)
    39  		if rows != 0 && math.Abs(newRatio-preferred_ratio) > math.Abs(ratio-preferred_ratio) {
    40  			continue
    41  		}
    42  
    43  		ratio = newRatio
    44  		cols = c
    45  		rows = r
    46  	}
    47  
    48  	if rows == 0 {
    49  		r := calculateNumberOfRows(dataWords, eccWords, minCols)
    50  		if r < minRows {
    51  			rows = minRows
    52  			cols = minCols
    53  		}
    54  	}
    55  
    56  	return
    57  }
    58  

View as plain text