diff --git a/EpsonPrintService/EpsonPrintService.csproj b/EpsonPrintService/EpsonPrintService.csproj
index a87410f..0f39dc9 100644
--- a/EpsonPrintService/EpsonPrintService.csproj
+++ b/EpsonPrintService/EpsonPrintService.csproj
@@ -5,7 +5,7 @@
net8.0
enable
enable
- 1.0.3
+ 1.0.4
diff --git a/Inspectron.Epson/PrintServer/Printers/Utils/KitchenReceipt/KitchenReceiptConverter.cs b/Inspectron.Epson/PrintServer/Printers/Utils/KitchenReceipt/KitchenReceiptConverter.cs
index 521ac2c..e94ab2c 100644
--- a/Inspectron.Epson/PrintServer/Printers/Utils/KitchenReceipt/KitchenReceiptConverter.cs
+++ b/Inspectron.Epson/PrintServer/Printers/Utils/KitchenReceipt/KitchenReceiptConverter.cs
@@ -100,32 +100,84 @@ public class KitchenReceiptConverter
return commands;
}
- private static void PrintDish(Dish dish, List commands)
+ private void PrintDish(Dish dish, List commands)
{
- string dishLine = $"{dish.Number}x {dish.Name}";
+ string quantityPrefix = $"{dish.Number}x ";
string guestInfo = dish.GuestId.HasValue ? $"{dish.GuestId.Value} " : "";
+ string fullPrefix = guestInfo + quantityPrefix;
+ string fullLine = fullPrefix + dish.Name;
- //todo: add word wrap if guest id is present and guestInfo + dish line too long. add spaces in front of continued lines to align with dish name start position
+ if (fullLine.Length <= _lineWidth || string.IsNullOrEmpty(dish.Name))
+ {
+ commands.Add(new PrintCommand(fullLine) { IsTall = true });
+ }
+ else
+ {
+ int availableWidth = _lineWidth - fullPrefix.Length;
+ if (availableWidth <= 0)
+ {
+ // Prefix alone exceeds line width, print without wrapping
+ commands.Add(new PrintCommand(fullLine) { IsTall = true });
+ }
+ else
+ {
+ string continuationIndent = new string(' ', guestInfo.Length);
+ var words = dish.Name.Split(' ');
+ var lines = new List();
+ string currentLine = "";
- commands.Add(new PrintCommand(guestInfo+dishLine) {IsTall = true});
+ foreach (var word in words)
+ {
+ if (currentLine.Length == 0)
+ {
+ currentLine = word;
+ }
+ else if (currentLine.Length + 1 + word.Length <= availableWidth)
+ {
+ currentLine += " " + word;
+ }
+ else
+ {
+ lines.Add(currentLine);
+ currentLine = word;
+ }
+ }
+
+ if (currentLine.Length > 0)
+ {
+ lines.Add(currentLine);
+ }
+
+ // First line with full prefix
+ commands.Add(new PrintCommand(fullPrefix + lines[0]) { IsTall = true });
+
+ // Continuation lines with indent to align with dish name
+ for (int i = 1; i < lines.Count; i++)
+ {
+ commands.Add(new PrintCommand(continuationIndent + lines[i]) { IsTall = true });
+ }
+ }
+ }
// Modifications
if (dish.Modifications != null && (dish.Modifications.Removed.Any() || dish.Modifications.Added.Any()))
{
+ string modificationIndent = new string(' ', guestInfo.Length + 1);
foreach (var removed in dish.Modifications.Removed)
{
- commands.Add(new PrintCommand($" - {removed}", isBold:true) { IsTall = true });
+ commands.Add(new PrintCommand($"{modificationIndent}- {removed}", isBold:true) { IsTall = true });
}
foreach (var added in dish.Modifications.Added)
{
- commands.Add(new PrintCommand($" + {added}", isBold: true) { IsTall = true });
+ commands.Add(new PrintCommand($"{modificationIndent}+ {added}", isBold: true) { IsTall = true });
}
}
// SpecialInstruction
if (!string.IsNullOrEmpty(dish.Comment))
{
- commands.Add(new PrintCommand($" Comment: {dish.Comment}", isBold: true) { IsTall = true });
+ string commentIndent = new string(' ', guestInfo.Length);
+ commands.Add(new PrintCommand($"{commentIndent}Comment: {dish.Comment}", isBold: true) { IsTall = true });
}
//commands.Add(new PrintCommand($""));