Skip to content

Commit

Permalink
Complete development of QR code in multiple colors.
Browse files Browse the repository at this point in the history
  • Loading branch information
KangSpace committed Sep 17, 2022
1 parent b67e8f3 commit 8c0c3db
Show file tree
Hide file tree
Showing 24 changed files with 241 additions and 176 deletions.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ Micro QRCode supports 4 character modes, and 4 versions with 4 Error correction
qrcode, err := NewQRCode(data)
outFileName := "/opt/temp/numeric.png"
if err == nil{
// set color for qrcode
// out := output.NewOutput(&output.BaseOutput{Type: output.PNG, Size: 400, CodeColor: output.ColorfulCodeColor})
out := output.NewPNGOutput0()
qrcode.Encode(out,outFileName)
}
Expand Down Expand Up @@ -103,23 +105,27 @@ Micro QRCode supports 4 character modes, and 4 versions with 4 Error correction
Create a new QRCode(Model2) by input data with auto-size Quiet Zone, default is 4x modules per side.

e.g.:
![alphanumeric qrcode with auto quiet zone](doc/images/qr/alphanumeric_auto_quietzone.jpg)
![alphanumeric qrcode with auto quiet zone](doc/images/qr/alphanumeric_auto_quietzone.jpg)

QRCode with color:

![byte_colorful_200x200.png](doc/images/qr/byte_colorful_200x200.png)


* [NewMicroQRCode(content string) (*mode.QRCodeStruct,error)](qrcode.go)

Create a new Micro QRCode by input data.

e.g.:
![numeric qrcode](doc/images/qr/numeric_micro_qrcode5.png)
![numeric qrcode](doc/images/qr/numeric_micro_qrcode5.png)


* [NewMicroQRCodeAutoQuiet(content string) (*mode.QRCodeStruct,error)](qrcode.go)

Create a new Micro QRCode by input data with auto-size Quiet Zone, default is 2x modules per side.

e.g.:
![byte_micro qrcode with auto quiet zone](doc/images/qr/byte_micro_qrcode15.png)
![byte_micro qrcode with auto quiet zone](doc/images/qr/byte_micro_qrcode15.png)


* [NewQRCode0(content string,format cons.Format,ec *mode.ErrorCorrection,m mode.Mode,quietZone *model.QuietZone) (qr *mode.QRCodeStruct,err error)](qrcode.go)
Expand Down Expand Up @@ -248,8 +254,8 @@ All QRCode test in [qrcode_test.go](test/qrcode_test.go) and [micro_qrcode_test.
<td rowspan="3">
Output
</td>
<td>Image File</td>
<td>2021-05-30</td>
<td>Image File<br/>(With Color)</td>
<td>2021-05-30<br/>(2022-09-17)</td>
</tr>
<tr >
<td>Base64 String</td>
Expand Down
12 changes: 12 additions & 0 deletions core/cons/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const (
NONE ErrorCorrectionLevel = -1 //-1
)

// QRCodeStructPart For example: alignmentPattern, FinderPattern...
type QRCodeStructPart = int

type ModeType = string

const (
Expand All @@ -38,6 +41,15 @@ const (
Fnc1ModeP2 ModeType = "FNC1_P2"
KanjiMode ModeType = "Kanji"
StructuredAppendMode ModeType = "Structured Append"

// QRCodeStructPart
DataPart QRCodeStructPart = 0
FinderPatternPart QRCodeStructPart = 1
AlignmentPart QRCodeStructPart = 2
QuietZonePart QRCodeStructPart = 3
TimingPatternPart QRCodeStructPart = 4
FormatPart QRCodeStructPart = 5
VersionPart QRCodeStructPart = 6
)

type Format = string
Expand Down
12 changes: 6 additions & 6 deletions core/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ import (

// Define log handle here

func Warn(msg interface{}){
func Warn(msg interface{}) {
fmt.Println("[WARN]", msg)
}

func Info(msg interface{}) {
fmt.Println("[INFO]", msg)
}

func Error(msg interface{}){
if _,ok:= msg.(error); ok {
func Error(msg interface{}) {
if _, ok := msg.(error); ok {
for i := 1; ; i++ {
pc, file, line, ok := runtime.Caller(i)
if !ok {
break
}
f := runtime.FuncForPC(pc)
if f.Name() != "runtime.main" && f.Name() != "runtime.goexit" {
fmt.Printf("[ERROR] %s %s (%d) %s \n",file,f.Name(), line, msg)
fmt.Printf("[ERROR] %s %s (%d) %s \n", file, f.Name(), line, msg)
}
}
}else{
} else {
fmt.Println("[ERROR] ", msg)
}
}
}
21 changes: 10 additions & 11 deletions core/mode/alphanumeric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,31 @@ import (

func TestChar(t *testing.T) {
data := "A"
fmt.Printf("data:%s,data[:1]:%s, data[0]:%s \n",data,data[:1],data[0:])
fmt.Printf("data:%s,data[:1]:%s, data[0]:%s \n", data, data[:1], data[0:])
data = "AB"
fmt.Printf("data:%s,data[:1]:%s, data[0]:%s \n",data,data[:1],data[0:])
fmt.Printf("data:%s,data[:1]:%s, data[0]:%s \n", data, data[:1], data[0:])
}

func TestByte(t *testing.T) {
data := "A"
fmt.Printf("data:%d \n",data[0])
fmt.Println("data:" + string( data[0]))
fmt.Printf("data:%d \n", data[0])
fmt.Println("data:" + string(data[0]))
}
func TestKanji(t *testing.T) {
data := "0日月"
if a ,err:=ToShiftJIS(data);err!= nil{
if a, err := ToShiftJIS(data); err != nil {
t.Fatal(err)
}else{
} else {
//aaa,err:= FromShiftJIS(a)
aaa:=strconv.Quote(a)
for _,v:= range strings.Split(aaa[1:len(aaa)-1],"\\x"){
aaa := strconv.Quote(a)
for _, v := range strings.Split(aaa[1:len(aaa)-1], "\\x") {
fmt.Printf("aaa:%v\n", v)
}
}


}

func transformEncoding( rawReader io.Reader, trans transform.Transformer) (string, error) {
func transformEncoding(rawReader io.Reader, trans transform.Transformer) (string, error) {
ret, err := ioutil.ReadAll(transform.NewReader(rawReader, trans))
if err == nil {
return string(ret), nil
Expand All @@ -55,4 +54,4 @@ func FromShiftJIS(str string) (string, error) {
// Convert a string encoding from UTF-8 to ShiftJIS
func ToShiftJIS(str string) (string, error) {
return transformEncoding(strings.NewReader(str), japanese.ShiftJIS.NewEncoder())
}
}
2 changes: 1 addition & 1 deletion core/mode/byte_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// 1. Byte mode is not available in Version M1 or M2 Micro QR Code Symbol.
// 2. Byte mode max capacity is 2953

const ByteRegExpType = "^.*$"
const ByteRegExpType = ".*"

type ByteMode struct {
*AbstractMode
Expand Down
3 changes: 1 addition & 2 deletions core/mode/eci_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ package mode
// --- ECI Designator(8,16 or 24 bits)
//


type ECI struct {
*AbstractMode
}

// TODO NOT IMPLEMENT
// TODO NOT IMPLEMENT
3 changes: 1 addition & 2 deletions core/mode/fnc1_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ package mode
// 1. FNC1 mode is not available for Micro QR Code Symbol.
//


type FNC1 struct {
*AbstractMode
}

// TODO NOT IMPLEMENT
// TODO NOT IMPLEMENT
23 changes: 16 additions & 7 deletions core/mode/kanji_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,28 @@ func (km *KanjiMode) IsSupport(data string) bool {
}
loop := dataLen / 2
for i := 0; i < loop; i++ {
twoByteInt := <-util.IteratorTwoByte(data)
if !(is8140To9FFC(twoByteInt)) &&
!(isE040ToEBBF(twoByteInt)) {
char := <-util.IteratorStringByte(data)
if !(is8140To9FFCChar(char)) &&
!(isE040ToEBBFChar(char)) {

return false
}
}
return true
}

func is8140To9FFC(twoByteInt uint16) bool {
return hex8140 <= twoByteInt && twoByteInt <= 0x9FFC
func is8140To9FFC(char uint16) bool {
return hex8140 <= char && char <= 0x9FFC
}
func isE040ToEBBF(twoByteInt uint16) bool {
return hexE040 <= twoByteInt && twoByteInt <= 0xEBBF

func is8140To9FFCChar(char rune) bool {
return hex8140 <= char && char <= 0x9FFC
}

func isE040ToEBBF(char uint16) bool {
return hexE040 <= char && char <= 0xEBBF
}

func isE040ToEBBFChar(char rune) bool {
return hexE040 <= char && char <= 0xEBBF
}
3 changes: 1 addition & 2 deletions core/mode/mixed_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ package mode
// The QR Code symbol may contain sequences of data in a combination of any of the modes described in 7.3.2 to 7.3.9.
// Micro QR Code symbols may contain sequences of data in a combination of any the modes available for the version of symbol and described in 7.3.3 to 7.3.7.


// TODO NOT IMPLEMENT
// TODO NOT IMPLEMENT
Loading

0 comments on commit 8c0c3db

Please sign in to comment.