Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/fonts/cursive.ttf
Binary file not shown.
Binary file added assets/fonts/dancing.ttf
Binary file not shown.
Binary file added assets/fonts/inter.ttf
Binary file not shown.
Binary file added assets/fonts/mono_space.ttf
Binary file not shown.
Binary file added assets/fonts/open_sans.ttf
Binary file not shown.
Binary file added assets/fonts/sans_serif_shade.ttf
Binary file not shown.
Binary file added assets/fonts/space_mono.ttf
Binary file not shown.
Binary file added assets/fonts/wind.ttf
Binary file not shown.
Binary file added assets/fonts/work_sans.ttf
Binary file not shown.
41 changes: 35 additions & 6 deletions lib/core/commands/command_factory/command_factory.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:paintroid/core/commands/command_implementation/graphic/text_command.dart';
import 'package:paintroid/core/commands/command_implementation/graphic/line_command.dart';
import 'package:paintroid/core/commands/command_implementation/graphic/path_command.dart';
import 'package:paintroid/core/commands/command_implementation/graphic/shape/circle_shape_command.dart';
import 'package:paintroid/core/commands/command_implementation/graphic/shape/ellipse_shape_command.dart';
import 'package:paintroid/core/commands/command_implementation/graphic/shape/square_shape_command.dart';
import 'package:paintroid/core/commands/command_implementation/graphic/spray_command.dart';
import 'package:paintroid/core/commands/path_with_action_history.dart';
Expand Down Expand Up @@ -33,12 +33,41 @@ class CommandFactory {
) =>
SquareShapeCommand(paint, topLeft, topRight, bottomLeft, bottomRight);

CircleShapeCommand createCircleShapeCommand(
EllipseShapeCommand createEllipseShapeCommand(
Paint paint,
double radius,
double radiusX,
double radiusY,
Offset center,
double angle,
) =>
CircleShapeCommand(paint, radius, center);
EllipseShapeCommand(
paint,
radiusX,
radiusY,
center,
angle: angle,
);

TextCommand createTextCommand(
Offset point,
String text,
TextStyle style,
double fontSize,
Paint paint,
double rotationAngle, {
double scaleX = 1.0,
double scaleY = 1.0,
}) =>
TextCommand(
point,
text,
style,
fontSize,
paint,
rotationAngle: rotationAngle,
scaleX: scaleX,
scaleY: scaleY,
);

SprayCommand createSprayCommand(List<Offset> points, Paint paint) {
return SprayCommand(points, paint);
Expand Down
9 changes: 6 additions & 3 deletions lib/core/commands/command_implementation/command.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'package:equatable/equatable.dart';
import 'package:paintroid/core/commands/command_implementation/graphic/line_command.dart';
import 'package:paintroid/core/commands/command_implementation/graphic/path_command.dart';
import 'package:paintroid/core/commands/command_implementation/graphic/shape/circle_shape_command.dart';
import 'package:paintroid/core/commands/command_implementation/graphic/shape/ellipse_shape_command.dart';
import 'package:paintroid/core/commands/command_implementation/graphic/shape/square_shape_command.dart';
import 'package:paintroid/core/commands/command_implementation/graphic/text_command.dart';
import 'package:paintroid/core/json_serialization/versioning/serializer_version.dart';

abstract class Command with EquatableMixin {
Expand All @@ -19,8 +20,10 @@ abstract class Command with EquatableMixin {
return LineCommand.fromJson(json);
case SerializerType.SQUARE_SHAPE_COMMAND:
return SquareShapeCommand.fromJson(json);
case SerializerType.CIRCLE_SHAPE_COMMAND:
return CircleShapeCommand.fromJson(json);
case SerializerType.ELLIPSE_SHAPE_COMMAND:
return EllipseShapeCommand.fromJson(json);
case SerializerType.TEXT_COMMAND:
return TextCommand.fromJson(json);
default:
return PathCommand.fromJson(json);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// ignore_for_file: must_be_immutable

import 'dart:ui';

import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:paintroid/core/commands/command_implementation/graphic/shape/shape_command.dart';
import 'package:paintroid/core/json_serialization/converter/offset_converter.dart';
import 'package:paintroid/core/json_serialization/converter/paint_converter.dart';
import 'package:paintroid/core/json_serialization/versioning/serializer_version.dart';
import 'package:paintroid/core/json_serialization/versioning/version_strategy.dart';

part 'ellipse_shape_command.g.dart';

@JsonSerializable()
class EllipseShapeCommand extends ShapeCommand {
double radiusX;
double radiusY;
@OffsetConverter()
Offset center;
final double angle;
final int version;
final String type;

EllipseShapeCommand(
super.paint,
this.radiusX,
this.radiusY,
this.center, {
this.angle = 0.0,
int? version,
this.type = SerializerType.ELLIPSE_SHAPE_COMMAND,
}) : version = version ??
VersionStrategyManager.strategy.getEllipseShapeCommandVersion();

@override
void call(Canvas canvas) {
canvas.save();
canvas.translate(center.dx, center.dy);
canvas.rotate(angle);

final Rect ovalRect = Rect.fromCenter(
center: Offset.zero,
width: radiusX * 2,
height: radiusY * 2,
);
canvas.drawOval(ovalRect, paint);
canvas.restore();
}

@override
List<Object?> get props =>
[paint, radiusX, radiusY, center, angle, version, type];

@override
Map<String, dynamic> toJson() => _$EllipseShapeCommandToJson(this);

factory EllipseShapeCommand.fromJson(Map<String, dynamic> json) {
int version = json['version'] as int;

switch (version) {
case Version.v1:
return _$EllipseShapeCommandFromJson(json);
case Version.v2:
// For different versions of SquareShapeCommand the deserialization
// has to be implemented manually.
// Autogenerated code can only be used for one version
default:
return _$EllipseShapeCommandFromJson(json);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

95 changes: 95 additions & 0 deletions lib/core/commands/command_implementation/graphic/text_command.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// ignore_for_file: must_be_immutable

import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:paintroid/core/commands/command_implementation/graphic/graphic_command.dart';
import 'package:paintroid/core/json_serialization/converter/text_style_converter.dart';
import 'package:paintroid/core/json_serialization/converter/offset_converter.dart';
import 'package:paintroid/core/json_serialization/converter/paint_converter.dart';
import 'package:paintroid/core/json_serialization/versioning/serializer_version.dart';
import 'package:paintroid/core/json_serialization/versioning/version_strategy.dart';

part 'text_command.g.dart';

@JsonSerializable()
class TextCommand extends GraphicCommand with EquatableMixin {
@OffsetConverter()
Offset point;
@TextStyleConverter()
final TextStyle style;

final String text;
final double rotationAngle;
final int version;
final String type;
final double fontSize;
final double scaleX;
final double scaleY;

TextCommand(
this.point,
this.text,
this.style,
this.fontSize,
super.paint, {
required this.rotationAngle,
this.scaleX = 1.0,
this.scaleY = 1.0,
int? version,
this.type = SerializerType.TEXT_COMMAND,
}) : version =
version ?? VersionStrategyManager.strategy.getTextCommandVersion();

@override
void call(Canvas canvas) {
final textPainter = TextPainter(
text: TextSpan(text: text, style: style.copyWith(fontSize: fontSize)),
textDirection: TextDirection.ltr,
);

textPainter.layout(minWidth: 0, maxWidth: double.infinity);

canvas.save();
canvas.translate(point.dx, point.dy);
canvas.rotate(rotationAngle);
canvas.scale(scaleX, scaleY);
final textOffset = Offset(-textPainter.width / 2, -textPainter.height / 2);
textPainter.paint(canvas, textOffset);
canvas.restore();
}

@override
List<Object?> get props => [
point,
text,
style,
fontSize,
rotationAngle,
scaleX,
scaleY,
version,
type,
paint,
];

@override
bool get stringify => true;

@override
Map<String, dynamic> toJson() => _$TextCommandToJson(this);

factory TextCommand.fromJson(Map<String, dynamic> json) {
int version = json['version'] as int;
switch (version) {
case Version.v1:
return _$TextCommandFromJson(json);
case Version.v2:
// For different versions of PathCommand the deserialization
// has to be implemented manually.
// Autogenerated code can only be used for one version
default:
return _$TextCommandFromJson(json);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading