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
1 change: 1 addition & 0 deletions Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ componentDidMount() {
| QrCodeLevel: string |Property to be used with the appendQrCode command. Choose the format of the return value defined in [QrCodeLevel](#qrcodelevel) Example: ```{appendQrCode:'{BStar', QrCodeLevel:'H'}``` |
| cell: number | Property to be used with the appendQrCode command. QRCode Cell size. Default 4. Example: ```{appendQrCode:'{BStar', cell:8}``` |
| appendBitmap: string |Print command of the bitmap is generated and added to the command buffer. Takes a string image URI. This can be obtained via the camera or photo library or as a static resource saved on the phone memory. Additional Properties: diffusion, width, bothScale, rotation, absolutePosition, alignment. Example: ```{appendBitmap:uri, diffusion: true, width:576, bothScale: true}``` Example with absolutePosition: ```{appendBitmap:uri, diffusion: true, width:576, bothScale: true, absolutePosition: 40 }``` Example with alignment: ```{appendBitmap:uri, diffusion: true, width:576, bothScale: true, alignment:"Center" }``` |
| appendBitmapBase64: base64 string |Print command of the bitmap is generated and added to the command buffer. Takes a base64 string image URI. This can be obtained via the camera or photo library or as a static resource saved on the phone memory. Additional Properties: diffusion, width, bothScale, rotation, absolutePosition, alignment. Example: ```{appendBitmap:uri, diffusion: true, width:576, bothScale: true}``` Example with absolutePosition: ```{appendBitmap:uri, diffusion: true, width:576, bothScale: true, absolutePosition: 40 }``` Example with alignment: ```{appendBitmap:uri, diffusion: true, width:576, bothScale: true, alignment:"Center" }``` |
| appendBitmapText: string | Property to print text as a bitmap image. Takes a string that you want converted to a bitmap. Additional properties: width, font, fontSize, bothScale, alignment. Example: ```{appendBitmapText:text, fontSize:32, alignment:"Center"}```
| diffusion: boolean | Property to be used with the appendBitmap command. Random dither: true = Valid, false = Invalid. Default true. Example: ```{appendBitmap:uri, diffusion: false } ``` |
| bothScale: boolean| Property to be used with the appendBitmap command. Height is changed according to the conversion rate of the width property. true = Valid, false = Invalid. Default true. Example: ```{appendBitmap:uri, bothScale: true }``` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.text.TextPaint;
import android.net.Uri;
import android.provider.MediaStore;
import androidx.annotation.Nullable;
import android.text.StaticLayout;
import android.text.Layout;
import android.util.Base64;
Expand All @@ -32,7 +33,6 @@
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableType;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
Expand Down Expand Up @@ -162,15 +162,20 @@ public void connect(final String portName, final String emulation, final Boolean
String portSettings = getPortSettingsOption(emulation);
if (starIoExtManager != null && starIoExtManager.getPort() != null) {
starIoExtManager.disconnect(new IConnectionCallback() {
@Override
public void onConnected(ConnectResult connectResult) {
// Do nothing
}
@Override
public void onConnected(ConnectResult connectResult) {
if (connectResult == ConnectResult.Success || connectResult == ConnectResult.AlreadyConnected) {

@Override
public void onDisconnected() {
//Do nothing
}
promise.resolve("Printer Connected");

} else {
promise.reject("CONNECT_ERROR", "Error Connecting to the printer");
}
}
@Override
public void onDisconnected() {
//Do nothing
}
});
}
starIoExtManager = new StarIoExtManager(hasBarcodeReader ? StarIoExtManager.Type.WithBarcodeReader : StarIoExtManager.Type.Standard, portName, portSettings, 10000, context);
Expand Down Expand Up @@ -364,7 +369,7 @@ private boolean sendCommand(byte[] commands, StarIOPort port, Promise promise) {
} catch (InterruptedException e) {
}
if (port == null) { //Not connected or port closed
promise.reject("STARIO_PORT_EXCEPTION", "Unable to Open Port, Please Connect to the printer before sending commands");
promise.reject("STARIO_PORT_EXCEPTION", "Fail to Open Port, Please connect to the printer before sending commands. If connected, remove the printer and reconnect it.");
return false;
}

Expand Down Expand Up @@ -571,6 +576,8 @@ else if (command.hasKey("appendBytes")) {
builder.appendQrCodeWithAlignment(command.getString("appendQrCode").getBytes(encoding), qrCodeModel, qrCodeLevel, cell, alignmentPosition);
}else builder.appendQrCode(command.getString("appendQrCode").getBytes(encoding), qrCodeModel, qrCodeLevel, cell);
} else if (command.hasKey("appendBitmap")){
// This command has caused issues for Android in the past
// Leaving in as legacy but appendBitmapBase64 is added as newer, preferred alternative
ContentResolver contentResolver = context.getContentResolver();
String uriString = command.getString("appendBitmap");
boolean diffusion = (command.hasKey("diffusion")) ? command.getBoolean("diffusion") : true;
Expand All @@ -590,6 +597,29 @@ else if (command.hasKey("appendBytes")) {
} catch (Exception e) {
promise.reject("APPEND_BITMAP_EXCEPTION", e.getMessage());
}
} else if (command.hasKey("appendBitmapBase64")){
ContentResolver contentResolver = context.getContentResolver();
String _uriString = command.getString("appendBitmapBase64");
String uriString = _uriString.substring(_uriString.indexOf(",") + 1);
boolean diffusion = (command.hasKey("diffusion")) ? command.getBoolean("diffusion") : true;
int width = (command.hasKey("width")) ? command.getInt("width") : 576;
boolean bothScale = (command.hasKey("bothScale")) ? command.getBoolean("bothScale") : true;
ICommandBuilder.BitmapConverterRotation rotation = (command.hasKey("rotation")) ? getConverterRotation(command.getString("rotation")) : getConverterRotation("Normal");
try {
final byte[] decodedBytes = Base64.decode(uriString, Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(decodedBytes, 0, decodedBytes.length);
if(command.hasKey("absolutePosition")){
int position = command.getInt("absolutePosition");
builder.appendBitmapWithAbsolutePosition(bitmap, diffusion, width, bothScale, rotation, position);
}else if(command.hasKey("alignment")){
ICommandBuilder.AlignmentPosition alignmentPosition = getAlignment(command.getString("alignment"));
builder.appendBitmapWithAlignment(bitmap, diffusion, width, bothScale, rotation, alignmentPosition);
}else {
builder.appendBitmap(bitmap, diffusion, width, bothScale, rotation);
}
} catch (Exception e) {
promise.reject("APPEND_BITMAP_BASE64_EXCEPTION", e.getMessage());
}
} else if (command.hasKey("appendBitmapText")){
int fontSize = (command.hasKey("fontSize")) ? command.getInt("fontSize") : 25;
boolean diffusion = (command.hasKey("diffusion")) ? command.getBoolean("diffusion") : true;
Expand Down
7 changes: 7 additions & 0 deletions ios/Communication.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ + (BOOL)sendCommands:(NSData *)commands
while (YES) {
if (port == nil) {
title = @"Fail to Open Port";
message = @"Please connect to the printer before sending commands. If connected, remove the printer and reconnect it.";
break;
}

Expand Down Expand Up @@ -98,6 +99,7 @@ + (BOOL)sendCommandsDoNotCheckCondition:(NSData *)commands
while (YES) {
if (port == nil) {
title = @"Fail to Open Port";
message = @"Please connect to the printer before sending commands. If connected, remove the printer and reconnect it.";
break;
}

Expand Down Expand Up @@ -172,6 +174,7 @@ + (BOOL)parseDoNotCheckCondition:(ISCPParser *)parser
while (YES) {
if (port == nil) {
title = @"Fail to Open Port";
message = @"Please connect to the printer before sending commands. If connected, remove the printer and reconnect it.";
break;
}

Expand Down Expand Up @@ -276,6 +279,7 @@ + (BOOL)sendCommands:(NSData *)commands

if (port == nil) {
title = @"Fail to Open Port";
message = @"Please connect to the printer before sending commands. If connected, remove the printer and reconnect it.";
break;
}

Expand Down Expand Up @@ -375,6 +379,7 @@ + (BOOL)sendCommandsDoNotCheckCondition:(NSData *)commands

if (port == nil) {
title = @"Fail to Open Port";
message = @"Please connect to the printer before sending commands. If connected, remove the printer and reconnect it.";
break;
}

Expand Down Expand Up @@ -514,6 +519,7 @@ + (BOOL)disconnectBluetooth:(NSString *)modelName

if (port == nil) {
title = @"Fail to Open Port";
message = @"Please connect to the printer before sending commands. If connected, remove the printer and reconnect it.";
break;
}

Expand Down Expand Up @@ -623,6 +629,7 @@ + (BOOL)confirmSerialNumber:(NSString *)portName

if (port == nil) {
title = @"Fail to Open Port";
message = @"Please connect to the printer before sending commands. If connected, remove the printer and reconnect it.";
break;
}

Expand Down
20 changes: 20 additions & 0 deletions ios/RNStarPrnt.m
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,26 @@ -(void)appendCommands:(ISCBBuilder *)builder
}
else [builder appendBitmap:image diffusion:diffusion width:width bothScale:bothScale rotation:rotation];
}
else if ([command valueForKey:@"appendBitmapBase64"]) {
NSString *urlString = [command valueForKey:@"appendBitmapBase64"];
NSInteger width = ([command valueForKey:@"width"]) ? [[command valueForKey:@"width"] intValue] : 576;
BOOL diffusion = ([[command valueForKey:@"diffusion"] boolValue] == NO) ? NO : YES;
BOOL bothScale = ([[command valueForKey:@"bothScale"] boolValue] == NO) ? NO : YES;
SCBBitmapConverterRotation rotation = [self getBitmapConverterRotation:[command valueForKey:@"rotation"]];
NSData *imageData = [[NSData alloc] initWithBase64EncodedString:urlString options:0];

UIImage *image = [UIImage imageWithData:imageData];

if([command valueForKey:@"absolutePosition"]){
int position = ([[command valueForKey:@"absolutePosition"] intValue]) ? [[command valueForKey:@"absolutePosition"] intValue]: 40;
[builder appendBitmapWithAbsolutePosition:image diffusion:diffusion width:width bothScale:bothScale rotation:rotation position:position];
}
else if ([command valueForKey:@"alignment"]){
SCBAlignmentPosition alignment = [self getAlignment:[command valueForKey:@"alignment"]];
[builder appendBitmapWithAlignment:image diffusion:diffusion width:width bothScale:bothScale rotation:rotation position:alignment];
}
else [builder appendBitmap:image diffusion:diffusion width:width bothScale:bothScale rotation:rotation];
}
else if ([command valueForKey:@"appendBitmapText"]) {
NSString *text = [command valueForKey:@"appendBitmapText"];
NSInteger width = ([command valueForKey:@"width"]) ? [[command valueForKey:@"width"] intValue] : 576;
Expand Down