mirror of
				https://github.com/KevinMidboe/motdGO.git
				synced 2025-10-29 17:50:24 +00:00 
			
		
		
		
	comments and cleaning
This commit is contained in:
		
							
								
								
									
										6
									
								
								font.go
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								font.go
									
									
									
									
									
								
							| @@ -9,6 +9,8 @@ import ( | |||||||
| 	"strings" | 	"strings" | ||||||
| ) | ) | ||||||
|  |  | ||||||
|  | const defaultFontName string = "standard" | ||||||
|  |  | ||||||
| // Represents a single font | // Represents a single font | ||||||
| type font struct { | type font struct { | ||||||
| 	hardblank string | 	hardblank string | ||||||
| @@ -64,7 +66,7 @@ func (this *fontManager) loadBuildInFont() error { | |||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 	this.fontLib["default"] = font | 	this.fontLib[defaultFontName] = font | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -129,7 +131,7 @@ func (this *fontManager) getFont(fontName string) (*font, error) { | |||||||
| 	if !ok { | 	if !ok { | ||||||
| 		err := this.loadDiskFont(fontName) | 		err := this.loadDiskFont(fontName) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			font, _ := this.fontLib["default"] | 			font, _ := this.fontLib[defaultFontName] | ||||||
| 			return font, nil | 			return font, nil | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|   | |||||||
							
								
								
									
										47
									
								
								render.go
									
									
									
									
									
								
							
							
						
						
									
										47
									
								
								render.go
									
									
									
									
									
								
							| @@ -7,44 +7,53 @@ import ( | |||||||
| 	"strings" | 	"strings" | ||||||
| ) | ) | ||||||
|  |  | ||||||
|  | // RenderOptions are used to set color or maybe future | ||||||
|  | // options to the AsciiRenderer | ||||||
| type RenderOptions struct { | type RenderOptions struct { | ||||||
| 	FontName string // font name | 	// Name of the used font | ||||||
|  | 	FontName string | ||||||
| 	FontColor []color.Attribute // every ascii byte's color | 	// Colors of the font | ||||||
|  | 	FontColor []color.Attribute | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // Create new RenderOptions | ||||||
|  | // Sets the default font name | ||||||
| func NewRenderOptions() *RenderOptions { | func NewRenderOptions() *RenderOptions { | ||||||
| 	opt := &RenderOptions{} | 	return &RenderOptions{ | ||||||
| 	opt.FontName = "default" | 		FontName: defaultFontName, | ||||||
| 	return opt | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // AsciiRender is the wrapper to render a string | ||||||
| type AsciiRender struct { | type AsciiRender struct { | ||||||
|  | 	// FontManager to store all the fonts | ||||||
| 	fontMgr *fontManager | 	fontMgr *fontManager | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // Create a new AsciiRender | ||||||
| func NewAsciiRender() *AsciiRender { | func NewAsciiRender() *AsciiRender { | ||||||
| 	this := &AsciiRender{} | 	return &AsciiRender{ | ||||||
|  | 		fontMgr: newFontManager(), | ||||||
| 	this.fontMgr = newFontManager() | 	} | ||||||
| 	return this |  | ||||||
| } | } | ||||||
|  |  | ||||||
| // walk through the path, load all the *.flf font file | // Loading all *.flf font files recursively in a path | ||||||
| func (this *AsciiRender) LoadFont(fontPath string) error { | func (ar *AsciiRender) LoadFont(fontPath string) error { | ||||||
| 	return this.fontMgr.loadFont(fontPath) | 	return ar.fontMgr.loadFont(fontPath) | ||||||
| } | } | ||||||
|  |  | ||||||
| // render with default options | // Render a string with the default options | ||||||
| func (this *AsciiRender) Render(asciiStr string) (string, error) { | func (ar *AsciiRender) Render(str string) (string, error) { | ||||||
| 	return this.render(asciiStr, NewRenderOptions()) | 	return ar.render(str, NewRenderOptions()) | ||||||
| } | } | ||||||
|  |  | ||||||
| // render with options | // Render a string with special RenderOptions | ||||||
| func (this *AsciiRender) RenderOpts(asciiStr string, opts *RenderOptions) (string, error) { | func (ar *AsciiRender) RenderOpts(str string, opts *RenderOptions) (string, error) { | ||||||
| 	return this.render(asciiStr, opts) | 	return ar.render(str, opts) | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| func (this *AsciiRender) convertChar(font *font, char rune) ([]string, error) { | func (this *AsciiRender) convertChar(font *font, char rune) ([]string, error) { | ||||||
|  |  | ||||||
| 	if char < 0 || char > 127 { | 	if char < 0 || char > 127 { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user