Skip to content

Commit

Permalink
feat: release v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-virkus committed Feb 6, 2023
1 parent efb9195 commit f1ba391
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 73 deletions.
15 changes: 15 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"cSpell.words": [
"doublestruck",
"figlet",
"fullwidth",
"grayscale",
"hardblank",
"hardblanks",
"smush",
"smushed",
"Smushes",
"smushing",
"strikethrough"
]
}
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.1.0
- update dependencies and improve documentation

## 1.0.0
- `enough_ascii_art` is now [null safe](https://dart.dev/null-safety/tour) #127
- removed integration of fonts, as this is not supported by Dart
Expand Down
15 changes: 1 addition & 14 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1 @@
# Defines a default set of lint rules enforced for
# projects at Google. For details and rationale,
# see https://github.com/dart-lang/pedantic#enabled-lints.
include: package:pedantic/analysis_options.yaml

# For lint rules and documentation, see http://dart-lang.github.io/linter/lints.
# Uncomment to specify additional rules.
# linter:
# rules:
# - camel_case_types

analyzer:
# exclude:
# - path/to/excluded/files/**
include: package:lints/recommended.yaml
55 changes: 32 additions & 23 deletions lib/enough_ascii_art.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
/// Brought to you by π”Όπ•Ÿπ• π•¦π•˜π•™ π•Šπ• π•—π•₯𝕨𝕒𝕣𝕖
library enough_ascii_art;

import 'package:enough_ascii_art/src/figlet/figlet.dart';
import 'package:enough_ascii_art/src/figlet/font.dart';
import 'package:enough_ascii_art/src/unicode_font_converter.dart';
import 'package:image/image.dart';
import 'src/figlet/figlet.dart';
import 'src/figlet/font.dart';
import 'src/image_converter.dart';
import 'src/emoticon_converter.dart';
import 'src/unicode_font_converter.dart';

export 'src/image_converter.dart';
export 'src/emoticon_converter.dart';
Expand All @@ -25,22 +24,26 @@ const String _asciiGrayScaleCharacters = '#@%=+*:-. ';
///
/// [image] the image to be converted
/// [maxWidth] the optional maximum width of the image in characters, defaults to 80
/// [maxHeight] the optional maximum height of th eimage in characters, defaults to null, so the image is caled linearily
/// [charSet] the optional charset from darkest to lightest character, defaults to '#@%=+*:-. '
/// [invert] allows to invert pixels, so that a dark pixel gets a bright characater and vise versa. This is useful when printing bight text on a dark background (console). Defaults to false.
/// [maxHeight] the optional maximum height of th image in characters, defaults to null, so the image is called linearly
/// [charset] the optional charset from darkest to lightest character, defaults to '#@%=+*:-. '
/// [invert] allows to invert pixels, so that a dark pixel gets a bright character and vise versa. This is useful when printing bight text on a dark background (console). Defaults to false.
/// [fontHeightCompensationFactor] the optional factor between 0 and 1 that is used to adjust the height of the image. Most fonts have a greater height than width, so this factor allows to compensate this. Defaults to 0.6.
String convertImage(Image image,
{int maxWidth = 80,
int? maxHeight,
String charset = _asciiGrayScaleCharacters,
bool invert = false,
double fontHeightCompensationFactor = 0.6}) {
return ImageConverter.convertImage(image,
maxWidth: maxWidth,
maxHeight: maxHeight,
charset: charset,
invert: invert,
fontHeightCompensationFactor: fontHeightCompensationFactor);
String convertImage(
Image image, {
int maxWidth = 80,
int? maxHeight,
String charset = _asciiGrayScaleCharacters,
bool invert = false,
double fontHeightCompensationFactor = 0.6,
}) {
return ImageConverter.convertImage(
image,
maxWidth: maxWidth,
maxHeight: maxHeight,
charset: charset,
invert: invert,
fontHeightCompensationFactor: fontHeightCompensationFactor,
);
}

/// Replaces all common smileys with their ASCII representation
Expand All @@ -52,15 +55,21 @@ String convertEmoticons(String text,
return EmoticonConverter.convertEmoticons(text, style);
}

/// Rendes the given [text] in the specified [font].
/// Renders the given [text] in the specified [font].
///
/// Optionally specify the [direction], which defaults to [FigletRenderDirection.LeftToRight]
String renderFiglet(String text, Font font,
{FigletRenderDirection direction = FigletRenderDirection.LeftToRight}) {
/// Optionally specify the [direction], which defaults to [FigletRenderDirection.leftToRight]
String renderFiglet(
String text,
Font font, {
FigletRenderDirection direction = FigletRenderDirection.leftToRight,
}) {
return FIGlet.renderFIGure(text, font, direction: direction);
}

/// Renders the given [text] in the specified [font].
String renderUnicode(String text, UnicodeFont font) {
String renderUnicode(
String text,
UnicodeFont font,
) {
return UnicodeFontConverter.encode(text, font);
}
8 changes: 4 additions & 4 deletions lib/src/figlet/figlet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import 'package:enough_ascii_art/src/figlet/renderer.dart';

import 'font.dart';

enum FigletRenderDirection { LeftToRight, TopToBottom }
enum FigletRenderDirection { leftToRight, topToBottom }

/// Helper class to render a FIGure
class FIGlet {
/// Rendes the given [text] in the specified [font].
/// Renders the given [text] in the specified [font].
///
/// Optionally specify the [direction], which defaults to [FigletRenderDirection.LeftToRight]
/// Optionally specify the [direction], which defaults to [FigletRenderDirection.leftToRight]
static String renderFIGure(String text, Font font,
{FigletRenderDirection direction = FigletRenderDirection.LeftToRight}) {
{FigletRenderDirection direction = FigletRenderDirection.leftToRight}) {
var renderer = Renderer();
return renderer.render(text, font, direction);
}
Expand Down
24 changes: 12 additions & 12 deletions lib/src/figlet/renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class Renderer {
/// [text] the text to render
/// [font] the FIGlet font to be used for rendering
/// [maxLineWidth] the optional maximum width for a single line, currently ignored
/// [horizontalLayouts] the optional rules for horizontal layouting
/// [verticalLayouts] the options rules for vertical layouting, currently ignored
/// [horizontalLayouts] the optional rules for horizontal layout
/// [verticalLayouts] the options rules for vertical layout, currently ignored
String render(
String text,
Font font,
Expand All @@ -21,7 +21,7 @@ class Renderer {
List<VerticalLayout>? verticalLayouts,
}) {
horizontalLayouts ??= font.horizontalLayouts;
if (direction == FigletRenderDirection.LeftToRight) {
if (direction == FigletRenderDirection.leftToRight) {
return _renderLR(text, font, horizontalLayouts!);
} else {
return _renderTB(text, font);
Expand Down Expand Up @@ -78,8 +78,8 @@ class _RenderLine {
static const int _runeRightBracket = 93; // ]
static const int _runeLeftBrace = 123; // {
static const int _runeRightBrace = 125; // }
static const int _runeLeftParenthese = 40; // (
static const int _runeRightParenthese = 41; // )
static const int _runeLeftParenthesis = 40; // (
static const int _runeRightParenthesis = 41; // )
static const int _runeForwardSlash = 47; // /
static const int _runeBackwardSlash = 92; // \
static const int _runeSmallerThan = 60; // <
Expand All @@ -95,8 +95,8 @@ class _RenderLine {
_runeRightBracket,
_runeLeftBrace,
_runeRightBrace,
_runeLeftParenthese,
_runeRightParenthese,
_runeLeftParenthesis,
_runeRightParenthesis,
_runeSmallerThan,
_runeLargerThan
];
Expand Down Expand Up @@ -221,10 +221,10 @@ class _RenderLine {
rightRune == _runeRightBrace) || // {}
(leftRune == _runeRightBrace &&
rightRune == _runeLeftBrace) || // }{
(leftRune == _runeLeftParenthese &&
rightRune == _runeRightParenthese) || // ()
(leftRune == _runeRightParenthese &&
rightRune == _runeLeftParenthese)) // )(
(leftRune == _runeLeftParenthesis &&
rightRune == _runeRightParenthesis) || // ()
(leftRune == _runeRightParenthesis &&
rightRune == _runeLeftParenthesis)) // )(
{
// replace right character:
isLayoutRuleAppliedForLine = true;
Expand Down Expand Up @@ -259,7 +259,7 @@ class _RenderLine {

// Universal smushing simply overrides the sub-character from the earlier FIGcharacter with the sub-character
// from the later FIGcharacter.
// This produces an "overlapping" effect with some FIGfonts, wherin the latter FIGcharacter may appear to be "in front".
// This produces an "overlapping" effect with some FIGfonts, wherein the latter FIGcharacter may appear to be "in front".
case HorizontalLayout.universalSmushing:
isLayoutRuleAppliedForLine = true;
break;
Expand Down
13 changes: 6 additions & 7 deletions lib/src/image_converter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import 'package:image/image.dart';
class ImageConverter {
static const String _asciiGrayScaleCharacters = '#@%=+*:-. ';

/// Converts the image to ASCII text.
/// Converts the [image] to ASCII text.
///
/// [image] the image to be converted
/// [maxWidth] the optional maximum width of the image in characters, defaults to 80
/// [maxHeight] the optional maximum height of the image in characters, defaults to null, so the image is scaled linearily
/// [charSet] the optional charset from darkest to lightest character, defaults to '#@%=+*:-. '
/// [invert] allows to invert pixels, so that a dark pixel gets a bright characater and vise versa. This is useful when printing bight text on a dark background (console). Defaults to false.
/// [maxWidth] the optional maximum width of the image in characters, defaults to `80`
/// [maxHeight] the optional maximum height of the image in characters, defaults to null, so the image is scaled linearly
/// [charset] the optional charset from darkest to lightest character, defaults to '#@%=+*:-. '
/// [invert] allows to invert pixels, so that a dark pixel gets a bright character and vise versa. This is useful when printing bight text on a dark background (console). Defaults to false.
/// [fontHeightCompensationFactor] the optional factor between 0 and 1 that is used to adjust the height of the image. Most fonts have a greater height than width, so this factor allows to compensate this. Defaults to 0.6.
static String convertImage(Image image,
{int maxWidth = 80,
Expand All @@ -35,8 +35,7 @@ class ImageConverter {
for (var y = 0; y < scaledImage.height; y++) {
for (var x = 0; x < scaledImage.width; x++) {
var pixel = scaledImage.getPixel(x, y);
var grayscale =
(pixel >> 16 & 0xff) | (pixel >> 8 & 0xff) | (pixel & 0xff);
var grayscale = (pixel.r as int) | (pixel.g as int) | (pixel.b as int);
var index = (grayscale * (charset.length - 1) / 255).floor();
if (invert) {
index = (charset.length - 1) - index;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/unicode_font_converter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,14 @@ class UnicodeFontConverter {
final to = _fonts[toFont]!;
final buffer = StringBuffer();
final characters = Characters(text);
characters.forEach((element) {
for (final element in characters) {
final index = from.indexOf(element);
if (index == -1) {
buffer.write(element);
} else {
buffer.write(to[index]);
}
});
}
return buffer.toString();
}

Expand Down
13 changes: 7 additions & 6 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
name: enough_ascii_art
description: Generates ASCII art using image to ASCII, FIGlet text banner support and emoticon to text conversions.
version: 1.0.0
description: Generates ASCII art using image to ASCII, FIGlet text banner
support and emoticon to text conversions.
version: 1.1.0
homepage: https://github.com/Enough-Software/enough_ascii_art

environment:
sdk: '>=2.12.0 <3.0.0'

dependencies:
image: ^3.0.5
characters: ^1.1.0

image: ^4.0.0

dev_dependencies:
pedantic: ^1.8.0
test: ^1.6.0
lints: ^2.0.1
test: ^1.22.0
11 changes: 6 additions & 5 deletions test/enough_ascii_art_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:enough_ascii_art/enough_ascii_art.dart';
import 'package:enough_ascii_art/src/unicode_font_converter.dart';
import 'package:test/test.dart';

void main() {
Expand All @@ -21,13 +20,15 @@ void main() {
group('Unicode font tests', () {
test('Convert to double struck', () {
expect(
UnicodeFontConverter.encode('hello world', UnicodeFont.doublestruck),
'𝕙𝕖𝕝𝕝𝕠 𝕨𝕠𝕣𝕝𝕕');
UnicodeFontConverter.encode('hello world', UnicodeFont.doublestruck),
'𝕙𝕖𝕝𝕝𝕠 𝕨𝕠𝕣𝕝𝕕',
);
});
test('Convert to fraktur', () {
expect(
UnicodeFontConverter.encode('hello world', UnicodeFont.frakturBold),
'π–π–Šπ–‘π–‘π–” π–œπ–”π–—π–‘π–‰');
UnicodeFontConverter.encode('hello world', UnicodeFont.frakturBold),
'π–π–Šπ–‘π–‘π–” π–œπ–”π–—π–‘π–‰',
);
});
});
}

0 comments on commit f1ba391

Please sign in to comment.