Skip to content

IOS上弹幕描边带尖刺? #7

Description

@MCDFsteve

很奇怪。同一份代码,其中macOS的描边宽度是3,IOS和Android设为的1.5.
但是手机上显示出来就有奇怪的尖刺,不知道是因为什么导致的。
尖刺容易出现在字的尖锐处(例如大写的M,2的左下角)
0e4d4a1458ac068dc795877ee4ea1d24

8a46b15e186ffc53ab2336fc639112e9
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import 'danmaku_content_item.dart';
import 'dart:io'; // 用于检测平台

double getStrokeWidth() {
  if (Platform.isIOS || Platform.isAndroid) {
    return 1.5; // 如果是iOS或Android设备
  } else {
    return 3.0; // 其他平台,例如Web、桌面
  }
}
class Utils {
  static generateParagraph(
      DanmakuContentItem content, double danmakuWidth, double fontSize) {
    final ui.ParagraphBuilder builder = ui.ParagraphBuilder(ui.ParagraphStyle(
      textAlign: TextAlign.left,
      fontSize: fontSize,
      textDirection: TextDirection.ltr,
    ))
      ..pushStyle(ui.TextStyle(
        color: content.color,
      ))
      ..addText(content.text);
    return builder.build()
      ..layout(ui.ParagraphConstraints(width: danmakuWidth));
  }

  static generateStrokeParagraph(
      DanmakuContentItem content, double danmakuWidth, double fontSize) {
    final Paint strokePaint = Paint()
      ..style = PaintingStyle.stroke
      ..strokeWidth = getStrokeWidth()
      ..color = (content.color == Colors.black || content.color.value == const Color.fromARGB(255, 0, 0, 0).value)
          ? Colors.white
          : Colors.black;

    final ui.ParagraphBuilder strokeBuilder =
        ui.ParagraphBuilder(ui.ParagraphStyle(
      textAlign: TextAlign.left,
      fontSize: fontSize,
      textDirection: TextDirection.ltr,
    ))
          ..pushStyle(ui.TextStyle(
            foreground: strokePaint,
          ))
          ..addText(content.text);

    return strokeBuilder.build()
      ..layout(ui.ParagraphConstraints(width: danmakuWidth));
  }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions