Implemented awful fallback bold and italic
This commit is contained in:
		
							parent
							
								
									e4c7dcb2e1
								
							
						
					
					
						commit
						e753fc11ca
					
				| @ -130,17 +130,18 @@ func (backend *Backend) drawRune ( | ||||
| 				backend.boundsOfCell(x, y)) | ||||
| 		} | ||||
| 
 | ||||
| 		// cue a series of pointless optimizations | ||||
| 		alphaMask, isAlpha := mask.(*image.Alpha) | ||||
| 		if isAlpha { | ||||
| 			backend.sprayRuneMaskAlpha ( | ||||
| 				alphaMask, destinationRectangle, | ||||
| 				maskPoint, foreground, background) | ||||
| 		} else { | ||||
| 		// alphaMask, isAlpha := mask.(*image.Alpha) | ||||
| 		// if isAlpha { | ||||
| 			// backend.sprayRuneMaskAlpha ( | ||||
| 				// alphaMask, destinationRectangle, | ||||
| 				// maskPoint, foreground, background) | ||||
| 		// } else { | ||||
| 			backend.sprayRuneMask ( | ||||
| 				mask, destinationRectangle, | ||||
| 				maskPoint, foreground, background) | ||||
| 		} | ||||
| 				maskPoint, foreground, background, | ||||
| 				runeStyle & stone.StyleItalic > 0, | ||||
| 				runeStyle & stone.StyleBold   > 0) | ||||
| 		// } | ||||
| 	} | ||||
| 
 | ||||
| 	// underline | ||||
| @ -161,54 +162,81 @@ func (backend *Backend) sprayRuneMask ( | ||||
| 	maskPoint  image.Point, | ||||
| 	fill       xgraphics.BGRA, | ||||
| 	background xgraphics.BGRA, | ||||
| 	italic     bool, | ||||
| 	bold       bool, | ||||
| ) { | ||||
| 	maxX := bounds.Max.X - bounds.Min.X | ||||
| 	maxY := bounds.Max.Y - bounds.Min.Y | ||||
| 	 | ||||
| 	for y := 0; y < maxY; y ++ { | ||||
| 	for x := 0; x < maxX; x ++ { | ||||
| 		_, _, _, | ||||
| 		alpha := mask.At(x + maskPoint.X, y + maskPoint.Y).RGBA() | ||||
| 		backend.canvas.SetBGRA ( | ||||
| 			x + bounds.Min.X, | ||||
| 			y + bounds.Min.Y - backend.metrics.descent, | ||||
| 			xgraphics.BlendBGRA ( | ||||
| 				background, | ||||
| 				xgraphics.BGRA { | ||||
| 					R: fill.R, | ||||
| 					G: fill.G, | ||||
| 					B: fill.B, | ||||
| 					A: uint8(alpha >> 8), | ||||
| 				})) | ||||
| 	}} | ||||
| 		var previousAlpha uint32 | ||||
| 		offset := 0 | ||||
| 		if italic { | ||||
| 			offset = (maxY - y) / 4 | ||||
| 		} | ||||
| 		for x := 0; x < maxX; x ++ { | ||||
| 			_, _, _, | ||||
| 			alpha := mask.At(x + maskPoint.X, y + maskPoint.Y).RGBA() | ||||
| 			currentAlpha := alpha | ||||
| 			if bold && previousAlpha > alpha { | ||||
| 				alpha = previousAlpha | ||||
| 			} | ||||
| 			backend.canvas.SetBGRA ( | ||||
| 				x + bounds.Min.X + offset, | ||||
| 				y + bounds.Min.Y - backend.metrics.descent, | ||||
| 				xgraphics.BlendBGRA ( | ||||
| 					background, | ||||
| 					xgraphics.BGRA { | ||||
| 						R: fill.R, | ||||
| 						G: fill.G, | ||||
| 						B: fill.B, | ||||
| 						A: uint8(alpha >> 8), | ||||
| 					})) | ||||
| 			previousAlpha = currentAlpha | ||||
| 		} | ||||
| 
 | ||||
| 		if bold { | ||||
| 			backend.canvas.SetBGRA ( | ||||
| 				bounds.Max.X + offset, | ||||
| 				y + bounds.Min.Y - backend.metrics.descent, | ||||
| 				xgraphics.BlendBGRA ( | ||||
| 					background, | ||||
| 					xgraphics.BGRA { | ||||
| 						R: fill.R, | ||||
| 						G: fill.G, | ||||
| 						B: fill.B, | ||||
| 						A: uint8(previousAlpha >> 8), | ||||
| 					})) | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (backend *Backend) sprayRuneMaskAlpha ( | ||||
| 	mask       *image.Alpha, | ||||
| 	bounds     image.Rectangle, | ||||
| 	maskPoint  image.Point, | ||||
| 	fill       xgraphics.BGRA, | ||||
| 	background xgraphics.BGRA, | ||||
| ) { | ||||
| 	maxX := bounds.Max.X - bounds.Min.X | ||||
| 	maxY := bounds.Max.Y - bounds.Min.Y | ||||
| 	 | ||||
| 	for y := 0; y < maxY; y ++ { | ||||
| 	for x := 0; x < maxX; x ++ { | ||||
| 		alpha := mask.AlphaAt(x + maskPoint.X, y + maskPoint.Y).A | ||||
| 		backend.canvas.SetBGRA ( | ||||
| 			x + bounds.Min.X, | ||||
| 			y + bounds.Min.Y - backend.metrics.descent, | ||||
| 			xgraphics.BlendBGRA ( | ||||
| 				background, | ||||
| 				xgraphics.BGRA { | ||||
| 					R: fill.R, | ||||
| 					G: fill.G, | ||||
| 					B: fill.B, | ||||
| 					A: alpha, | ||||
| 				})) | ||||
| 	}} | ||||
| } | ||||
| // func (backend *Backend) sprayRuneMaskAlpha ( | ||||
| 	// mask       *image.Alpha, | ||||
| 	// bounds     image.Rectangle, | ||||
| 	// maskPoint  image.Point, | ||||
| 	// fill       xgraphics.BGRA, | ||||
| 	// background xgraphics.BGRA, | ||||
| // ) { | ||||
| 	// maxX := bounds.Max.X - bounds.Min.X | ||||
| 	// maxY := bounds.Max.Y - bounds.Min.Y | ||||
| 	//  | ||||
| 	// for y := 0; y < maxY; y ++ { | ||||
| 	// for x := 0; x < maxX; x ++ { | ||||
| 		// alpha := mask.AlphaAt(x + maskPoint.X, y + maskPoint.Y).A | ||||
| 		// backend.canvas.SetBGRA ( | ||||
| 			// x + bounds.Min.X, | ||||
| 			// y + bounds.Min.Y - backend.metrics.descent, | ||||
| 			// xgraphics.BlendBGRA ( | ||||
| 				// background, | ||||
| 				// xgraphics.BGRA { | ||||
| 					// R: fill.R, | ||||
| 					// G: fill.G, | ||||
| 					// B: fill.B, | ||||
| 					// A: alpha, | ||||
| 				// })) | ||||
| 	// }} | ||||
| // } | ||||
| 
 | ||||
| func fillRectangle ( | ||||
| 	source      image.Image, | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user