mirror of
				https://github.com/esimov/pigo.git
				synced 2025-10-31 11:26:47 +08:00 
			
		
		
		
	Include vendor dependencies
This commit is contained in:
		
							
								
								
									
										58
									
								
								vendor/github.com/fogleman/gg/wrap.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								vendor/github.com/fogleman/gg/wrap.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,58 @@ | ||||
| package gg | ||||
|  | ||||
| import ( | ||||
| 	"strings" | ||||
| 	"unicode" | ||||
| ) | ||||
|  | ||||
| type measureStringer interface { | ||||
| 	MeasureString(s string) (w, h float64) | ||||
| } | ||||
|  | ||||
| func splitOnSpace(x string) []string { | ||||
| 	var result []string | ||||
| 	pi := 0 | ||||
| 	ps := false | ||||
| 	for i, c := range x { | ||||
| 		s := unicode.IsSpace(c) | ||||
| 		if s != ps && i > 0 { | ||||
| 			result = append(result, x[pi:i]) | ||||
| 			pi = i | ||||
| 		} | ||||
| 		ps = s | ||||
| 	} | ||||
| 	result = append(result, x[pi:]) | ||||
| 	return result | ||||
| } | ||||
|  | ||||
| func wordWrap(m measureStringer, s string, width float64) []string { | ||||
| 	var result []string | ||||
| 	for _, line := range strings.Split(s, "\n") { | ||||
| 		fields := splitOnSpace(line) | ||||
| 		if len(fields)%2 == 1 { | ||||
| 			fields = append(fields, "") | ||||
| 		} | ||||
| 		x := "" | ||||
| 		for i := 0; i < len(fields); i += 2 { | ||||
| 			w, _ := m.MeasureString(x + fields[i]) | ||||
| 			if w > width { | ||||
| 				if x == "" { | ||||
| 					result = append(result, fields[i]) | ||||
| 					x = "" | ||||
| 					continue | ||||
| 				} else { | ||||
| 					result = append(result, x) | ||||
| 					x = "" | ||||
| 				} | ||||
| 			} | ||||
| 			x += fields[i] + fields[i+1] | ||||
| 		} | ||||
| 		if x != "" { | ||||
| 			result = append(result, x) | ||||
| 		} | ||||
| 	} | ||||
| 	for i, line := range result { | ||||
| 		result[i] = strings.TrimSpace(line) | ||||
| 	} | ||||
| 	return result | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 esimov
					esimov