Bidi 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
<加護病房</h2 的 h2>Bidi 演算法>
This is an implementation of the Unicode Bidirectional Algorithm.
[Android.Runtime.Register("android/icu/text/Bidi", ApiSince=29, DoNotGenerateAcw=true)]
public class Bidi : Java.Lang.Object
[<Android.Runtime.Register("android/icu/text/Bidi", ApiSince=29, DoNotGenerateAcw=true)>]
type Bidi = class
inherit Object
- 繼承
- 屬性
備註
<加護病房</h2 的 h2>Bidi 演算法>
這是 Unicode 雙向演算法的實作。 該演算法定義於 Unicode 標準附錄 #9。
注意:執行雙向演算法並相應重新排序字串的函式庫有時被稱為「儲存佈局引擎」。 ICU 的 Bidi 與 Shaping(阿拉伯式塑造)類別可作為此類「儲存佈局引擎」的核心使用。
<h3>關於 API 的一般評論:</h3>
該 &limit”一連串字元中,是緊接在最後一個字元之後的位置,也就是比該位置多一個。
部分 API 方法提供存取 &runs“。 真是個”run”定義為執行 Bidi 演算法後,處於相同嵌入層級的字元序列。
<h3>基本概念:段落</h3> 一段文字可依字元分割成多個段落,使用 Bidi 類別 Block Separator。 關於段落的處理,請參見:<ul><li>#countParagraphs<li>#getParaLevel<li>#getParagraph<li>#getParagraphByIndex</ul>
<h3>基本概念:文本方向</h3> 一段文字的方向可能是:<ul><li<#LTR>li<#RTL>li<>#MIXEDli>#NEUTRAL</ul>
<h3>基本概念:等級</h3>
此 API 中的層級代表根據 Unicode 雙向演算法的嵌入層級。 它們的低階位元(偶數/奇數值)表示視覺方向。
當用於 paraLevel 和 embeddingLevelssetPara() 參數時,層級可以是抽象值;其中:<ul><li>是值的高embeddingLevels[]階位元,表示使用應用程式是否指定字元的層級,以覆蓋 Bidi 實作所解析的值。</li><li>paraLevel 可以設定為偽層級值LEVEL_DEFAULT_LTR和LEVEL_DEFAULT_RTL。</li></ul>
相關的常數並非真實且有效的電平值。
DEFAULT_XXX 可以用來指定段落層級的預設值, setPara() 表示方法何時決定該層級,但輸入中沒有強型別字元。
請注意,的 LEVEL_DEFAULT_LTR 值是偶數,而的 LEVEL_DEFAULT_RTL 值是奇數,就像一般的長期關係(LTR)和現實生活(RTL)水準值一樣——這些特殊值就是這樣設計的。 此外,實作假設MAX_EXPLICIT_LEVEL是奇數。
注意:相關常數的數值不會改變:它們與使用 7 位元元組值(加上覆寫位元)及本 API 中的位元組資料型態綁定。
<b>參見:</b<>ul<>li#LEVEL_DEFAULT_LTR><li li#LEVEL_OVERRIDE>#LEVEL_DEFAULT_RTL<><li li#MAX_EXPLICIT_LEVEL<><>#setPara/ul>
<h3>基本概念:重排序模式</h3> 重排序模式值指示應使用哪種 Bidi 演算法變體。
<b>另見:</b><ul<>li><#setReorderingModeli><#REORDER_DEFAULTli#REORDER_NUMBERS_SPECIAL<>li li#REORDER_GROUP_NUMBERS_WITH_R><li#REORDER_INVERSE_LIKE_DIRECT<>>#REORDER_INVERSE_FOR_NUMBERS_SPECIAL><<#REORDER_RUNS_ONLY>#REORDER_INVERSE_NUMBERS_AS_L</ul>
<h3>基本概念:重排選項</h3> 重排選項可在 Bidi 文字轉換時套用。
<b>參見:</b<>ul<>li#setReorderingOptions><li li#OPTION_INSERT_MARKS>#OPTION_DEFAULT<><li li#OPTION_REMOVE_CONTROLS<><>#OPTION_STREAMING/ul>
<h4> ICU Bidi API <範例程式碼 /h4>
<h5>使用 ICU Bidi API</h5 渲染段落>
這是(假設性的)範例程式碼,說明 ICU Bidi API 如何用來渲染一段文字。 渲染程式碼高度依賴圖形系統,因此範例程式碼必須做出許多假設,這些假設可能與任何現有圖形系統的屬性相符,也可能不符。
基本假設如下:
<ul><li>渲染是從左到右在水平線上完成的。</li><li>可以一次渲染一系列單樣式、單向文字。 </li><li>這樣的文字序列會以邏輯順序的字元(代碼單元)傳送到圖形系統。</li><li>換行演算法非常複雜且依賴位置,因此其實作未包含在本範例程式碼中。</li></ul>
package android.icu.dev.test.bidi;
import android.icu.text.Bidi;
import android.icu.text.BidiRun;
public class Sample {
static final int styleNormal = 0;
static final int styleSelected = 1;
static final int styleBold = 2;
static final int styleItalics = 4;
static final int styleSuper=8;
static final int styleSub = 16;
static class StyleRun {
int limit;
int style;
public StyleRun(int limit, int style) {
this.limit = limit;
this.style = style;
}
}
static class Bounds {
int start;
int limit;
public Bounds(int start, int limit) {
this.start = start;
this.limit = limit;
}
}
static int getTextWidth(String text, int start, int limit,
StyleRun[] styleRuns, int styleRunCount) {
// simplistic way to compute the width
return limit - start;
}
// set limit and StyleRun limit for a line
// from text[start] and from styleRuns[styleRunStart]
// using Bidi.getLogicalRun(...)
// returns line width
static int getLineBreak(String text, Bounds line, Bidi para,
StyleRun styleRuns[], Bounds styleRun) {
// dummy return
return 0;
}
// render runs on a line sequentially, always from left to right
// prepare rendering a new line
static void startLine(byte textDirection, int lineWidth) {
System.out.println();
}
// render a run of text and advance to the right by the run width
// the text[start..limit-1] is always in logical order
static void renderRun(String text, int start, int limit,
byte textDirection, int style) {
}
// We could compute a cross-product
// from the style runs with the directional runs
// and then reorder it.
// Instead, here we iterate over each run type
// and render the intersections -
// with shortcuts in simple (and common) cases.
// renderParagraph() is the main function.
// render a directional run with
// (possibly) multiple style runs intersecting with it
static void renderDirectionalRun(String text, int start, int limit,
byte direction, StyleRun styleRuns[],
int styleRunCount) {
int i;
// iterate over style runs
if (direction == Bidi.LTR) {
int styleLimit;
for (i = 0; i < styleRunCount; ++i) {
styleLimit = styleRuns[i].limit;
if (start < styleLimit) {
if (styleLimit > limit) {
styleLimit = limit;
}
renderRun(text, start, styleLimit,
direction, styleRuns[i].style);
if (styleLimit == limit) {
break;
}
start = styleLimit;
}
}
} else {
int styleStart;
for (i = styleRunCount-1; i >= 0; --i) {
if (i > 0) {
styleStart = styleRuns[i-1].limit;
} else {
styleStart = 0;
}
if (limit >= styleStart) {
if (styleStart < start) {
styleStart = start;
}
renderRun(text, styleStart, limit, direction,
styleRuns[i].style);
if (styleStart == start) {
break;
}
limit = styleStart;
}
}
}
}
// the line object represents text[start..limit-1]
static void renderLine(Bidi line, String text, int start, int limit,
StyleRun styleRuns[], int styleRunCount) {
byte direction = line.getDirection();
if (direction != Bidi.MIXED) {
// unidirectional
if (styleRunCount <= 1) {
renderRun(text, start, limit, direction, styleRuns[0].style);
} else {
renderDirectionalRun(text, start, limit, direction,
styleRuns, styleRunCount);
}
} else {
// mixed-directional
int count, i;
BidiRun run;
try {
count = line.countRuns();
} catch (IllegalStateException e) {
e.printStackTrace();
return;
}
if (styleRunCount <= 1) {
int style = styleRuns[0].style;
// iterate over directional runs
for (i = 0; i < count; ++i) {
run = line.getVisualRun(i);
renderRun(text, run.getStart(), run.getLimit(),
run.getDirection(), style);
}
} else {
// iterate over both directional and style runs
for (i = 0; i < count; ++i) {
run = line.getVisualRun(i);
renderDirectionalRun(text, run.getStart(),
run.getLimit(), run.getDirection(),
styleRuns, styleRunCount);
}
}
}
}
static void renderParagraph(String text, byte textDirection,
StyleRun styleRuns[], int styleRunCount,
int lineWidth) {
int length = text.length();
Bidi para = new Bidi();
try {
para.setPara(text,
textDirection != 0 ? Bidi.LEVEL_DEFAULT_RTL
: Bidi.LEVEL_DEFAULT_LTR,
null);
} catch (Exception e) {
e.printStackTrace();
return;
}
byte paraLevel = (byte)(1 & para.getParaLevel());
StyleRun styleRun = new StyleRun(length, styleNormal);
if (styleRuns == null || styleRunCount <= 0) {
styleRuns = new StyleRun[1];
styleRunCount = 1;
styleRuns[0] = styleRun;
}
// assume styleRuns[styleRunCount-1].limit>=length
int width = getTextWidth(text, 0, length, styleRuns, styleRunCount);
if (width <= lineWidth) {
// everything fits onto one line
// prepare rendering a new line from either left or right
startLine(paraLevel, width);
renderLine(para, text, 0, length, styleRuns, styleRunCount);
} else {
// we need to render several lines
Bidi line = new Bidi(length, 0);
int start = 0, limit;
int styleRunStart = 0, styleRunLimit;
for (;;) {
limit = length;
styleRunLimit = styleRunCount;
width = getLineBreak(text, new Bounds(start, limit),
para, styleRuns,
new Bounds(styleRunStart, styleRunLimit));
try {
line = para.setLine(start, limit);
} catch (Exception e) {
e.printStackTrace();
return;
}
// prepare rendering a new line
// from either left or right
startLine(paraLevel, width);
if (styleRunStart > 0) {
int newRunCount = styleRuns.length - styleRunStart;
StyleRun[] newRuns = new StyleRun[newRunCount];
System.arraycopy(styleRuns, styleRunStart, newRuns, 0,
newRunCount);
renderLine(line, text, start, limit, newRuns,
styleRunLimit - styleRunStart);
} else {
renderLine(line, text, start, limit, styleRuns,
styleRunLimit - styleRunStart);
}
if (limit == length) {
break;
}
start = limit;
styleRunStart = styleRunLimit - 1;
if (start >= styleRuns[styleRunStart].limit) {
++styleRunStart;
}
}
}
}
public static void main(String[] args)
{
renderParagraph("Some Latin text...", Bidi.LTR, null, 0, 80);
renderParagraph("Some Hebrew text...", Bidi.RTL, null, 0, 60);
}
}
Java 文件 android.icu.text.Bidi。
本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。
建構函式
| 名稱 | Description |
|---|---|
| Bidi() |
分配一個 |
| Bidi(Char[], Int32, Byte[], Int32, Int32, BidiOptions) |
從給定的文字、嵌入和方向資訊中建立 Bidi。 |
| Bidi(IAttributedCharacterIterator) |
從給定的段落中建立 Bidi。 |
| Bidi(Int32, Int32) |
將 |
| Bidi(IntPtr, JniHandleOwnership) |
建立一個受管理實例,代表一個現有的 Java 物件。 |
| Bidi(String, BidiOptions) |
從給定的段落文字和基底方向建立 Bidi。 |
欄位
| 名稱 | Description |
|---|---|
| DirectionDefaultLeftToRight |
已淘汰.
常數表示根據 Unicode 雙向演算法,基礎方向依賴於文本中第一個強方向字元。 |
| DirectionDefaultRightToLeft |
已淘汰.
常數表示根據 Unicode 雙向演算法,基礎方向依賴於文本中第一個強方向字元。 |
| DirectionLeftToRight |
已淘汰.
常數表示基底方向為左至右。 |
| DirectionRightToLeft |
已淘汰.
常數表示基底方向為右至左。 |
| DoMirroring |
write 選項位元Reordered(): 在 RTL 中以「鏡像」屬性替換字元,透過其鏡像映射執行 |
| InsertLrmForNumeric |
option 位元用於 writeReordered():如有需要,用 LRM 包圍執行;這是近似「反比迪」演算法的一部分 |
| KeepBaseCombining |
write 的選項位元:在 RTL 執行基本角色後,繼續合併角色 |
| LevelDefaultLtr |
段落層級設定 |
| LevelDefaultRtl |
段落層級設定 |
| LevelOverride |
位元標誌用於電平輸入。 |
| Ltr |
從左到右的文字。 |
| MapNowhere |
已淘汰.
當邏輯索引沒有對應的視覺索引時,映射方法可返回特殊值,反之亦然。 |
| MaxExplicitLevel |
最大明確嵌入層級。 |
| Mixed |
混合方向文字。 |
| Neutral |
沒有強烈指向性的文字。 |
| OptionDefault |
已淘汰.
選項值 |
| OptionInsertMarks |
已淘汰.
選項位元: |
| OptionRemoveControls |
已淘汰.
選項位 |
| OptionStreaming |
已淘汰.
選項位元: |
| OutputReverse |
選項位元用於寫入Reordered(): 將輸出以反向順序寫入 |
| RemoveBidiControls |
write 選項位元Reordered(): 移除 Bidi 控制字元(這不影響 INSERT_LRM_FOR_NUMERIC) |
| ReorderDefault |
重排序模式:根據 Unicode 採用的規則邏輯轉視覺 Bidi 演算法。 |
| ReorderGroupNumbersWithR |
重排序模式:邏輯轉換為視覺化演算法,將數字與相鄰的 R 字元分組(可逆演算法)。 |
| ReorderInverseForNumbersSpecial |
重排序模式:Bidi 演算法的反向 Bidi(視覺轉邏輯)演算法 |
| ReorderInverseLikeDirect |
重排序模式:視覺轉邏輯演算法,等同於一般的邏輯轉視覺演算法。 |
| ReorderInverseNumbersAsL |
重排序模式:從視覺轉邏輯演算法,處理像 L 這類數字(與 所 |
| ReorderNumbersSpecial |
重排模式:邏輯到視覺化的演算法,以模仿 Windows XP 的行為方式處理數字。 |
| ReorderRunsOnly |
重排序模式:重序僅用於將邏輯 LTR 字串轉換成邏輯 RTL 字串,或反之亦然。 |
| Rtl |
從右到左的文字。 |
屬性
| 名稱 | Description |
|---|---|
| BaseLevel |
返回基準層級(從左到右為 0,從右至左為 1)。 |
| Class |
回傳此 |
| CustomClassifier |
取得目前用於 Bidi 類別判定的自訂類別分類器。 -或- 設定一個由 UBA 實作用於 Bidi 類別判定的自訂 Bidi 分類器。 |
| Direction |
了解文字的方向性。 |
| Handle |
底層 Android 實例的帳號。 (繼承來源 Object) |
| Inverse |
這個 |
| IsLeftToRight |
如果該行全是從左到右的文字,且基底方向是從左到右,則回傳 true。 |
| IsMixed |
若線不是從左到右或從右到左,則回傳 true。 |
| IsOrderParagraphsLTR |
這個 |
| IsRightToLeft |
如果該行全是右至左文字,且基底方向為右至左,則回傳 true。 |
| JniIdentityHashCode |
取得由互通執行時指派給此 Java 對等端的身份雜湊碼。 (繼承來源 Object) |
| JniManagedPeerState |
取得執行時最後指派的狀態旗標。 (繼承來源 JavaObject) |
| JniPeerMembers |
取得用於存取此 Java 綁定成員的 JNI 元資料。 |
| Length |
了解文字長度。 |
| ParaLevel |
取得文本的段落層級。 |
| PeerReference |
取得這個 Java 節點的 JNI 物件參考。 (繼承來源 Object) |
| ProcessedLength |
取得最後一次呼叫 |
| ReorderingMode |
對於特定 Bidi 物件,請求的重排序模式是什麼? -或- 修改 Bidi 演算法的操作,使其實作基本 Bidi 演算法的某種變體,或近似一個「反 Bidi」演算法,取決於不同的「重排序模式」值。 |
| ReorderingOptions |
對特定 Bidi 物件套用哪些重新排序選項? -或- 指定在 Bidi 轉換時應應用哪些重排序選項。 |
| ResultLength |
取得最後一次呼叫 所 |
| RunCount |
回傳關卡次數。 |
| TextAsString |
拿簡訊。 |
| ThresholdClass |
取得用於虛擬方法派遣的 Java 類別。 |
| ThresholdType |
取得宣告這個 Java 綁定的受管理型別。 |
方法
| 名稱 | Description |
|---|---|
| BaseIsLeftToRight() |
若基底方向為左至右,則回傳真 |
| Clone() |
建立並回傳此物件的副本。 (繼承來源 Object) |
| Construct(JniObjectReference, JniObjectReferenceOptions) |
將此對等節點的建置委派給執行時的值管理器。 (繼承來源 JavaObject) |
| CountParagraphs() |
記錄段落數量。 |
| CountRuns() |
知道得分數。 |
| CreateLineBidi(Int32, Int32) |
建立一個 Bidi 物件,代表當前 Bidi 所代表段落中一行文字中的 bidi 資訊。 |
| Dispose() |
釋放該 Java 節點所持有的資源。 (繼承來源 Object) |
| Dispose(Boolean) |
釋放該 Java 節點所持有的資源。 (繼承來源 Object) |
| DisposeUnlessReferenced() |
請求值管理器處置此對等節點,除非其映射保留該受管理實例。 (繼承來源 JavaObject) |
| Equals(Object) |
測試另一個受管理節點是否參考相同的 Java 物件。 (繼承來源 JavaObject) |
| Equals(Object) |
表示是否有其他物體「等同」於此物。 (繼承來源 Object) |
| GetBaseDirection(ICharSequence) |
根據 Unicode 雙向演算法,取得文本的基本方向。 |
| GetBaseDirection(String) |
根據 Unicode 雙向演算法,取得文本的基本方向。 |
| GetCustomizedClass(Int32) |
取得給定碼點的 Bidi 類別。 |
| GetHashCode() |
回傳物件的雜湊碼值。 (繼承來源 Object) |
| GetLevelAt(Int32) |
先拿到一個角色的等級。 |
| GetLevels() |
為每個角色準備一系列等級。 |
| GetLogicalIndex(Int32) |
從視覺位置取得邏輯文本位置。 |
| GetLogicalMap() |
取得一個邏輯轉視覺索引映射(陣列),以呈現(段落或行)物件中的 |
| GetLogicalRun(Int32) |
跑個邏輯的跑。 |
| GetParagraph(Int32) |
拿一段文字,給出文本中的位置。 |
| GetParagraphByIndex(Int32) |
根據這段的索引,拿一段話。 |
| GetParagraphIndex(Int32) |
取得段落索引,並在文本中指定位置。 |
| GetRunLevel(Int32) |
回傳此行第 n 個邏輯運算的等級。 |
| GetRunLimit(Int32) |
回傳該行第 n 個邏輯執行結束後字元的索引,作為該行起點的偏移量。 |
| GetRunStart(Int32) |
回傳該行第 n 個邏輯運算起點字元的索引,作為該行起點的偏移量。 |
| GetText() |
拿簡訊。 |
| GetVisualIndex(Int32) |
從邏輯文字位置取得視覺位置。 |
| GetVisualMap() |
取得一個視覺到邏輯的索引映射(陣列),以呈現(段落或行)物件中的 |
| GetVisualRun(Int32) |
根據物件的索引取得 |
| InvertMap(Int32[]) |
將索引圖反轉。 |
| JavaFinalize() |
已淘汰.
當垃圾回收判定該物件不再有相關參考時,由垃圾回收器呼叫。 (繼承來源 Object) |
| Notify() |
喚醒一個正在該物件監視器上等待的執行緒。 (繼承來源 Object) |
| NotifyAll() |
喚醒所有等待該物件監視器的執行緒。 (繼承來源 Object) |
| OrderParagraphsLTR(Boolean) |
指定區塊分隔符是否必須分配為零層,使後續段落由左至右依序排列。 |
| ReorderLogical(Byte[]) |
這是一種不使用 |
| ReorderVisual(Byte[]) |
這是一種不使用 |
| ReorderVisually(Byte[], Int32, Object[], Int32, Int32) |
根據等級將陣列中的物件重新排列成視覺順序。 |
| RequiresBidi(Char[], Int32, Int32) |
若指定文本需要 bidi 分析,則回傳 true。 |
| SetContext(String, String) |
在呼叫 setPara() 之前,先設定上下文。 |
| SetHandle(IntPtr, JniHandleOwnership) |
設定 Handle 屬性。 (繼承來源 Object) |
| SetLine(Int32, Int32) |
|
| SetPara(Char[], SByte, Byte[]) |
執行 Unicode Bidi 演算法。 |
| SetPara(IAttributedCharacterIterator) |
對特定段落執行 Unicode Bidi 演算法,該演算法定義於 Unicode 標準附錄 #9,版本 13,亦見 Unicode 標準版本 4。 |
| SetPara(String, SByte, Byte[]) |
執行 Unicode Bidi 演算法。 |
| SetPeerReference(JniObjectReference, JniObjectReferenceOptions) |
在控制區塊中儲存參考值,但不建立 JNI 參考副本。 (繼承來源 JavaObject) |
| ToArray<T>() |
從這個 Java 陣列包裝器建立一個受管理陣列。 (繼承來源 Object) |
| ToString() |
回傳物件的字串表示。 (繼承來源 Object) |
| UnregisterFromRuntime() |
將此 Java 節點從互通執行時中取消註冊。 (繼承來源 Object) |
| Wait() |
導致目前執行緒等待被喚醒,通常是透過 <em>通知</><em 或 em>中斷</em> 來喚醒。 (繼承來源 Object) |
| Wait(Int64, Int32) |
會讓目前執行緒等待喚醒,通常是透過 <em>通知</><em 或 em>中斷</em>,或是經過一定的真實時間。 (繼承來源 Object) |
| Wait(Int64) |
會讓目前執行緒等待喚醒,通常是透過 <em>通知</><em 或 em>中斷</em>,或是經過一定的真實時間。 (繼承來源 Object) |
| WriteReordered(BidiOptions) |
取 |
| WriteReverse(String, BidiOptions) |
反轉右To-Left Unicode 文本。 |
明確介面實作
| 名稱 | Description |
|---|---|
| IJavaPeerable.Disposed() |
標記此節點為處置,並以 |
| IJavaPeerable.Finalized() |
標記此節點為處置,並以 |
| IJavaPeerable.JniObjectReferenceControlBlock |
取得此對等端使用的原生控制區塊指標。 (繼承來源 JavaObject) |
| IJavaPeerable.SetJniIdentityHashCode(Int32) |
儲存執行時提供的身份雜湊碼。 (繼承來源 JavaObject) |
| IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) |
取代儲存的受管理對等狀態旗標。 (繼承來源 JavaObject) |
| IJavaPeerable.SetPeerReference(JniObjectReference) |
當引用無效時,更新對等節點並釋放已拋棄節點的控制區塊。 (繼承來源 JavaObject) |
擴充方法
| 名稱 | Description |
|---|---|
| GetJniTypeName(IJavaPeerable) |
取得實例 |
| JavaAs<TResult>(IJavaPeerable) |
試著強制 |
| JavaCast<TResult>(IJavaObject) |
執行 Android 執行時檢查型別轉換。 |
| JavaCast<TResult>(IJavaObject) |
重用相容的受管理對等端或取得請求型態的包裝器。 |
| TryJavaCast<TResult>(IJavaPeerable, TResult) |
試著強制 |