Turbopower_ipro: Fix usage of "dir" attribute in TIpHtmlNodeCORE descendants (RTL).

This commit is contained in:
wp_xyz 2022-05-29 16:15:10 +02:00
parent da07d07593
commit 599b6f0df5
6 changed files with 106 additions and 9 deletions

View File

@ -4593,7 +4593,7 @@ begin
ClassId := aOwner.FindAttribute(htmlAttrCLASS);
Title := aOwner.FindAttribute(htmlAttrTITLE);
Style := aOwner.FindAttribute(htmlAttrSTYLE);
s := aOwner.FindAttribute(htmlAttrDIR);
s := Uppercase(aOwner.FindAttribute(htmlAttrDIR));
if (s = '') then
begin
if (ParentNode is TIpHtmlNodeCore) then

View File

@ -396,6 +396,8 @@ var
R : TRect;
CurElem : PIpHtmlElement;
CurWordInfo : PWordInfo;
isRTL: Boolean;
rtlNode: TIpHtmlNodeCORE;
begin
dx := CalcDelta;
ph := FIpHtml.PageHeight;
@ -447,7 +449,17 @@ begin
OffsetRect(R, dx + WDelta, 0);
{ mirroring for RTL reading }
if FOwner.Dir = hdRTL then
isRTL := (FOwner.Dir = hdRTL);
if (CurElem.Owner.ParentNode <> nil) and (CurElem.Owner.ParentNode is TIpHTMLNodeCORE) then
begin
rtlNode := TIpHtmlNodeCORE(CurElem.Owner.ParentNode);
if isRTL and (rtlNode.Dir = hdLTR) then
isRTL := false
else
if not isRTL and (rtlNode.Dir = hdRTL) then
isRTL := true;
end;
if isRTL then
R.SetLocation(FPageRect.Right - R.Right + FPageRect.Left, R.Top);
SetWordRect(CurElem, R);
@ -1247,6 +1259,8 @@ var
P : TPoint;
R : TRect;
TextStyle: TTextStyle;
isRTL: Boolean;
rtlNode: TIpHtmlNodeCORE;
OldBrushcolor: TColor;
OldFontColor: TColor;
OldFontStyle: TFontStyles;
@ -1305,8 +1319,17 @@ begin
FCanvas.Brush.Style := bsClear;
end;
if (FOwner.Dir = hdRTL) then
TextStyle.RightToLeft := true;
isRTL := (FOwner.Dir = hdRTL);
if (aCurWord.Owner.ParentNode <> nil) and (aCurWord.Owner.ParentNode is TIpHTMLNodeCORE) then
begin
rtlNode := TIpHtmlNodeCORE(aCurWord.Owner.ParentNode);
if isRTL and (rtlNode.Dir = hdLTR) then
isRTL := false
else
if not isRTL and (rtlNode.Dir = hdRTL) then
isRTL := true;
end;
TextStyle.RightToLeft := isRTL;
if aCurWord.Owner.ParentNode = aCurTabFocus then
FCanvas.DrawFocusRect(R);

View File

@ -404,6 +404,8 @@ var
CoreNode: TIpHtmlNodeCore;
TrNode: TIpHtmlNodeTR;
CellNode: TIpHtmlNodeTableHeaderOrCell;
isRTL: Boolean;
rtlNode: TIpHtmlNodeCORE;
begin
RowSp2 := TIntArr.Create;
try
@ -591,7 +593,17 @@ var
end;
{ mirroring for RTL reading }
if FOwner.Dir = hdRTL then
isRTL := (FOwner.Dir = hdRTL);
if (CellNode is TIpHTMLNodeCORE) then
begin
rtlNode := TIpHtmlNodeCORE(CellNode);
if isRTL and (rtlNode.Dir = hdLTR) then
isRTL := false
else
if not isRTL and (rtlNode.Dir = hdRTL) then
isRTL := true;
end;
if isRTL then
begin
CellNode.Dir := hdRTL;
CellRect1 := CellNode.PadRect;

View File

@ -747,7 +747,7 @@ const
//------------------------------------------------------------------------------
// Localization / Right-to-left
// Right-to-left
//------------------------------------------------------------------------------
const
Arab_title =
@ -760,9 +760,63 @@ const
' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' + LE +
'</head>' + LE +
'<body>' + LE +
'<div> لماذا ترتيب الكلمات معكوس </div> ' + LE +
' <div> لماذا ترتيب الكلمات معكوس </div> ' + LE +
'</body>' + LE +
'</html>';
Hebrew_title =
'Hebrew text (RTL in <html> tag)';
Hebrew_descr =
'Text should begin at right. Terminating period must be at left of last word.';
Hebrew_html =
'<html lang="he-IL" dir="rtl">' + LE +
'<body>' + LE +
' <div>אנא פנאי בהבנה צרפתית גם. בה ויקי פיסיקה חפש, מפתח המשפט אתה על. כתב ב ליצירתה ויקימדיה, בדף על בקרבת ייִדיש ליצירתה. גם אנא עקרונות התפתחות פוליטיקה, יוני מיותר בחירות אנא מה. או שנורו בישול ארץ, עזרה וקשקש קצרמרים או שער. מה זאת מיזם מדעי סטטיסטיקה. זכר אל היסטוריה אקטואליה, את כלים מיזמי מונחים מדע.</div>' + LE +
'</body>' + LE +
'</html>';
Hebrew_bodyRTL_title =
'Hebrew text (RTL in <body> tag)';
Hebrew_bodyRTL_descr =
'Text should begin at right. Terminating period must be at left of last word.';
Hebrew_bodyRTL_html =
'<html lang="he-IL">' + LE +
'<head>' + LE +
' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' + LE +
'</head>' + LE +
'<body dir="rtl">' + LE +
' <div>אנא פנאי בהבנה צרפתית גם. בה ויקי פיסיקה חפש, מפתח המשפט אתה על. כתב ב ליצירתה ויקימדיה, בדף על בקרבת ייִדיש ליצירתה. גם אנא עקרונות התפתחות פוליטיקה, יוני מיותר בחירות אנא מה. או שנורו בישול ארץ, עזרה וקשקש קצרמרים או שער. מה זאת מיזם מדעי סטטיסטיקה. זכר אל היסטוריה אקטואליה, את כלים מיזמי מונחים מדע.</div>' + LE +
'</body>' + LE +
'</html>';
Hebrew_divRTL_title =
'Hebrew text (RTL in <div> tag)';
Hebrew_divRTL_descr =
'Text should begin at right. Terminating period must be at left of last word.';
Hebrew_divRTL_html =
'<html>' + LE +
'<head>' + LE +
' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' + LE +
'</head>' + LE +
'<body>' + LE +
' <div dir="rtl">אנא פנאי בהבנה צרפתית גם. בה ויקי פיסיקה חפש, מפתח המשפט אתה על. כתב ב ליצירתה ויקימדיה, בדף על בקרבת ייִדיש ליצירתה. גם אנא עקרונות התפתחות פוליטיקה, יוני מיותר בחירות אנא מה. או שנורו בישול ארץ, עזרה וקשקש קצרמרים או שער. מה זאת מיזם מדעי סטטיסטיקה. זכר אל היסטוריה אקטואליה, את כלים מיזמי מונחים מדע.</div>' + LE +
'</body>' + LE +
'</html>';
Hebrew_pRTL_title =
'Hebrew text (RTL in <p> tag)';
Hebrew_pRTL_descr =
'Text should begin at right. Terminating period must be at left of last word.';
Hebrew_pRTL_html =
'<html>' + LE +
'<head>' + LE +
' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' + LE +
'</head>' + LE +
'<body>' + LE +
' <p dir="rtl">אנא פנאי בהבנה צרפתית גם. בה ויקי פיסיקה חפש, מפתח המשפט אתה על. כתב ב ליצירתה ויקימדיה, בדף על בקרבת ייִדיש ליצירתה. גם אנא עקרונות התפתחות פוליטיקה, יוני מיותר בחירות אנא מה. או שנורו בישול ארץ, עזרה וקשקש קצרמרים או שער. מה זאת מיזם מדעי סטטיסטיקה. זכר אל היסטוריה אקטואליה, את כלים מיזמי מונחים מדע.</p>' + LE +
'</body>' + LE +
'</html>';
implementation

View File

@ -257,8 +257,12 @@ begin
AddTest(node, NoBodyTag_title, NoBodyTag_descr, NoBodyTag_html);
node.Expanded := true;
node := TestTree.Items.AddChild(nil, 'Localization, right-to-left');
node := TestTree.Items.AddChild(nil, 'Right-to-left');
AddTest(node, Arab_title, Arab_descr, Arab_html);
AddTest(node, Hebrew_title, Hebrew_descr, Hebrew_html);
AddTest(node, Hebrew_bodyRTL_title, Hebrew_bodyRTL_descr, Hebrew_bodyRTL_html);
AddTest(node, Hebrew_divRTL_title, Hebrew_divRTL_descr, Hebrew_divRTL_html);
AddTest(node, Hebrew_pRTL_title, Hebrew_pRTL_descr, Hebrew_pRTL_html);
node.Expanded := true;
LoadResults;

View File

@ -35,4 +35,8 @@ dca07f136c5214df3052f67cc853e62a|1
93dd425a961945639cf1c85592e26843|0
09b8149415d34207aa8e95634d64469a|1
cc5bf5c55da8bb627046b09b0fcfb1ce|1
dfba0057569856f72bec2b26854d474b|1
f738db5e8941192ab14e0ecb485c8ed5|1
4c204e1fdd12a6f93badd0dd55b4da69|1
68af7a5a96a05d18d55eef5c3bf00a89|1
4fd8f73a6676e4967e653268ca3e7225|1
2e943290006b8273a3d2592c7632a6db|1