Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
shai-almog committed Apr 17, 2024
2 parents 2a5362e + 6ccb820 commit ae9d353
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
51 changes: 48 additions & 3 deletions Ports/iOSPort/nativeSources/IOSNative.m
Original file line number Diff line number Diff line change
Expand Up @@ -9682,9 +9682,7 @@ JAVA_INT drawLabelStringValign(CODENAME_ONE_THREAD_STATE, JAVA_OBJECT __cn1ThisO
return drawLabelString(threadStateData, __cn1ThisObject, nativeGraphics, nativeFont, str, x, y + iconStringHGap, textSpaceW, isTickerRunning, tickerShiftText, textDecoration, rtl, endsWith3Points, textWidth, fontHeight);
}
}




JAVA_VOID com_codename1_impl_ios_IOSImplementation_drawLabelComponent___java_lang_Object_int_int_int_int_com_codename1_ui_plaf_Style_java_lang_String_java_lang_Object_java_lang_Object_int_int_boolean_boolean_int_int_boolean_int_boolean_int(CODENAME_ONE_THREAD_STATE, JAVA_OBJECT __cn1ThisObject, JAVA_OBJECT nativeGraphics, JAVA_INT cmpX, JAVA_INT cmpY, JAVA_INT cmpHeight, JAVA_INT cmpWidth, JAVA_OBJECT style, JAVA_OBJECT text, JAVA_OBJECT icon, JAVA_OBJECT stateIcon, JAVA_INT preserveSpaceForState, JAVA_INT gap, JAVA_BOOLEAN rtl, JAVA_BOOLEAN isOppositeSide, JAVA_INT textPosition, JAVA_INT stringWidth, JAVA_BOOLEAN isTickerRunning, JAVA_INT tickerShiftText, JAVA_BOOLEAN endsWith3Points, JAVA_INT valign) {
JAVA_OBJECT font = com_codename1_ui_plaf_Style_getFont___R_com_codename1_ui_Font(threadStateData, style);
JAVA_OBJECT nativeFont = com_codename1_ui_Font_getNativeFont___R_java_lang_Object(threadStateData, font);
Expand Down Expand Up @@ -9932,3 +9930,50 @@ JAVA_VOID com_codename1_impl_ios_IOSNative_endBackgroundTask___long(CN1_THREAD_S
{
[[UIApplication sharedApplication] endBackgroundTask:(UIBackgroundTaskIdentifier)bgTask];
}

JAVA_BOOLEAN com_codename1_impl_ios_IOSNative_isRTLString___java_lang_String_R_boolean(CN1_THREAD_STATE_MULTI_ARG JAVA_OBJECT instanceObject, JAVA_OBJECT javaString)
{
POOL_BEGIN();
NSString *string = toNSString(CN1_THREAD_STATE_PASS_ARG javaString);
// Define Unicode ranges for Hebrew and Arabic
NSRange hebrewRange = NSMakeRange(0x0590, 0x05FF - 0x0590 + 1);
NSRange arabicRange = NSMakeRange(0x0600, 0x06FF - 0x0600 + 1);
// Range for common neutral characters (basic Latin, common punctuation, and digits)
NSRange neutralRange = NSMakeRange(0x0020, 0x007E - 0x0020 + 1);
// Emoji ranges (covering most common emoji blocks)
NSArray<NSValue *> *emojiRanges = @[
[NSValue valueWithRange:NSMakeRange(0x1F600, 0x1F64F - 0x1F600 + 1)], // Emoticons
[NSValue valueWithRange:NSMakeRange(0x1F300, 0x1F5FF - 0x1F300 + 1)], // Miscellaneous Symbols and Pictographs
[NSValue valueWithRange:NSMakeRange(0x1F900, 0x1F9FF - 0x1F900 + 1)], // Supplemental Symbols and Pictographs
[NSValue valueWithRange:NSMakeRange(0x2600, 0x26FF - 0x2600 + 1)] // Miscellaneous Symbols
];

NSUInteger length = [string length];
for (NSUInteger i = 0; i < length; i++) {
unichar c = [string characterAtIndex:i];
// Continue if the character is within the neutral or emoji ranges
BOOL isNeutralOrEmoji = (c >= neutralRange.location && c <= NSMaxRange(neutralRange));
for (NSValue *value in emojiRanges) {
NSRange range = [value rangeValue];
if (c >= range.location && c <= NSMaxRange(range)) {
isNeutralOrEmoji = YES;
break;
}
}
if (isNeutralOrEmoji) {
continue;
}
// Return true if the character is within the Hebrew or Arabic Unicode ranges
if ((c >= hebrewRange.location && c <= NSMaxRange(hebrewRange)) ||
(c >= arabicRange.location && c <= NSMaxRange(arabicRange))) {
POOL_END();
return YES;
}
// If the first significant character is not Hebrew or Arabic, return false
POOL_END();
return NO;
}

POOL_END();
return NO;
}
23 changes: 20 additions & 3 deletions Ports/iOSPort/src/com/codename1/impl/ios/IOSImplementation.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
import com.codename1.util.Callback;
import com.codename1.util.StringUtil;
import com.codename1.util.SuccessCallback;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Arrays;
Expand Down Expand Up @@ -150,6 +151,8 @@ public class IOSImplementation extends CodenameOneImplementation {
private boolean isActive=false;
private final ArrayList<Runnable> onActiveListeners = new ArrayList<Runnable>();
private static BackgroundFetch backgroundFetchCallback;

private boolean useContentBasedRTLStringDetection = false;


/**
Expand Down Expand Up @@ -342,7 +345,13 @@ public Vector getCookiesForURL(String url) {
return v;
}
return super.getCookiesForURL(url);
}
}

public void setPlatformHint(String key, String value) {
if ("platformHint.ios.useContentBasedRTLStringDetection".equals(key)) {
useContentBasedRTLStringDetection = Boolean.parseBoolean(value);
}
}

private boolean textEditorHidden;

Expand Down Expand Up @@ -1854,17 +1863,25 @@ public void drawString(Object graphics, String str, int x, int y) {
int l = str.length();
int max = fnt.getMaxStringLength();
if(l > max) {
boolean rtl = useContentBasedRTLStringDetection
? nativeInstance.isRTLString(str)
: UIManager.getInstance().getLookAndFeel().isRTL();
// really long string split it and draw multiple strings to avoid texture overload
int one = 1;
if(l % max == 0) {
one = 0;
}
if (rtl) {
x += stringWidth(fnt, str);
}
int stringCount = l / max + one;
for(int iter = 0 ; iter < stringCount ; iter++) {
int pos = iter * max;
String s = str.substring(pos, Math.min(pos + max, str.length()));
ng.nativeDrawString(ng.color, ng.alpha, fnt.peer, s, x, y);
x += stringWidth(fnt, s);
int substrWidth = stringWidth(fnt, s);
int rtlOffset = rtl ? -substrWidth : 0;
ng.nativeDrawString(ng.color, ng.alpha, fnt.peer, s, x + rtlOffset, y);
x += (rtl ? -substrWidth : substrWidth);
}
} else {
ng.nativeDrawString(ng.color, ng.alpha, fnt.peer, str, x, y);
Expand Down
1 change: 1 addition & 0 deletions Ports/iOSPort/src/com/codename1/impl/ios/IOSNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -719,5 +719,6 @@ native void nativeSetTransformMutable(

native int getDisplaySafeInsetBottom();

native boolean isRTLString(String javaString);

}

0 comments on commit ae9d353

Please sign in to comment.