void paintBackground(Canvas canvas, PaintRecord record, Offset baseOffset) { if (record.style.background == null) { return; } var metrics = record.metrics; Rect rect = Rect.fromLTRB(0, metrics.ascent, record.runWidth, metrics.descent); rect = rect.shift(record.shiftedOffset(baseOffset)); canvas.drawRect(rect, record.style.background); }
void paintDecorations(Canvas canvas, PaintRecord record, Offset baseOffset) { if (record.style.decoration == null || record.style.decoration == TextDecoration.none) { return; } if (record.style.decorationColor == null) { this._textPaint.color = record.style.color; } else { this._textPaint.color = record.style.decorationColor; } var width = record.runWidth; var metrics = record.metrics; float underLineThickness = metrics.underlineThickness ?? (record.style.fontSize / 14.0f); this._textPaint.style = PaintingStyle.stroke; this._textPaint.strokeWidth = underLineThickness; var recordOffset = record.shiftedOffset(baseOffset); var x = recordOffset.dx; var y = recordOffset.dy; int decorationCount = 1; switch (record.style.decorationStyle) { case TextDecorationStyle.doubleLine: decorationCount = 2; break; } var decoration = record.style.decoration; for (int i = 0; i < decorationCount; i++) { float yOffset = i * underLineThickness * kFloatDecorationSpacing; float yOffsetOriginal = yOffset; if (decoration != null && decoration.contains(TextDecoration.underline)) { // underline yOffset += metrics.underlinePosition ?? underLineThickness; canvas.drawLine(new Offset(x, y + yOffset), new Offset(x + width, y + yOffset), this._textPaint); yOffset = yOffsetOriginal; } if (decoration != null && decoration.contains(TextDecoration.overline)) { yOffset += metrics.ascent; canvas.drawLine(new Offset(x, y + yOffset), new Offset(x + width, y + yOffset), this._textPaint); yOffset = yOffsetOriginal; } if (decoration != null && decoration.contains(TextDecoration.lineThrough)) { yOffset += (decorationCount - 1.0f) * underLineThickness * kFloatDecorationSpacing / -2.0f; yOffset += metrics.strikeoutPosition ?? (metrics.fxHeight ?? 0) / -2.0f; canvas.drawLine(new Offset(x, y + yOffset), new Offset(x + width, y + yOffset), this._textPaint); yOffset = yOffsetOriginal; } } this._textPaint.style = PaintingStyle.fill; this._textPaint.strokeWidth = 0; }