DCSIMG
December 2008 - Posts - Maxim

December 2008 - Posts

(ניתן לראות פוסט זה עם תרגום לעברית)

Two weeks ago I've being asked to add a support for Hebrew texts in our last Silverlight project - "Com-Unit", this application is used by sport commentators and provides graphical presentation for real-time basketball statistics. Also displays some sportive "Trivia" about teams and players, this "Trivia" is written in Hebrew. I knew that it will lead to many problems, because MS didn't add (yet) RTL support in any version of Silverlight.

In "Ice Age of Silverlight 1.1" (couple months before Justin had published his library) I developed very simple "TextBlockWrapper" with primitive algorithm for Hebrew texts conversion and forgotten about it. I tried to implement this library and discovered that it's primitive algorithm can't be used with mixed texts (especially from sportive area).

It managed with texts like this:
image

But more complicated texts are messed:
image

I didn't have time and passion to deal with fixing of my algorithm, but remembered that somewhere are good men that developed Silverlight Library with RTL support for Hebrew and Arabic (Tamir, Justin, and others). This is quit good open source project with few bugs that can be fixed.

I found that "TextBlock" has some minor bugs:

Wrong display of properties in MS Blend 2.0:
image
(All properties that tagged [TypeConverter(typeof(EnumValueConverter<TextWrapping>))] can't be displayed properly)

All texts are wrapped badly (paragraphs are spliced in wrong places):
image 
(As you can see there is a lot of empty space on left side)
 

MS Blend crashed some times after changes in property grid of control:
image
(This one appeared when I tried to reset "Text" property)

In general this is good library, can be fixed and extended. I decided to mix good things from both projects and to fix small parts in "TextBlock".

My "TextBlockWrapper" is using original Silverlight "TextBlock" to measure strings for better text wrapping, so I made some changes:
image
(No text is sliced in right places and wrapped much better)

I added small class "StringFormatter" with 2 functions for paragraph splitting:

This one is measuring size of text, using "TextBlock" than expends it self by text:

public static Size MeasureString(string text, FontFamily fontFamily, double fontSize)
{
    // very important: use "System.Windows.Controls.TextBlock" from Silverlight
    // to avoid recursive call in "BiDiControls.TextBlock"
    var
textBlock = new Controls.TextBlock
                        {
                            FontFamily = fontFamily,
                            FontSize = fontSize,
                            Text = text
                        };
    return
new Size(textBlock.ActualWidth, textBlock.ActualHeight);
}

(Note: the function has some disadvantage - each call creates new instance of "TextBlock" control, any suggestion for improvement will be accepted with joy)

This one is splitting text into paragraphs (helps "TextBlock" to wrap RTL text properly):

public static string SplitParagraphs(string text, double targetWidth, FontFamily targetFontFamily, double targetFontSize)
{
    if (string.IsNullOrEmpty(text) || text.Length < 2) return text;
   
Size s = MeasureString(text, targetFontFamily, targetFontSize);
   
if (s.Width < targetWidth) return text;
   
int indents = (int) Math.Round(s.Width/targetWidth);
   
int length = text.Length/indents;
   
for (int i = 0; i < indents; i++)
   
{
       
int index = text.IndexOf(" ", length*(i + 1) - 1);
       
if (index < 0) continue;
       
text = text.Insert(index, "\r");
   
}
   
return text;
}

(Note: the function has some disadvantage - requires exact width of control, any suggestion for improvement will be accepted with joy)

The "BidiControls" uses "NBidi" algorithm (developed by good man: Itai Bar-Haim), now I use it in my small library.

Now my "TextBlockWrapper" displays mixed text in right way:
image
("NBidi" converts text with brackets, parenthesis and other stuff much better then mine - I'm lazy :), but you can see minor defect on right side of "TextBlock" - each sentence is padded with small space character, I don't know if it comes from "NBidi" or wrapped "TextBlock" has this problem, same problem we can see in "BidiControls" too)

image

"TextBlockWrapper":
image

 

Some properties are wrapping original properties of internal "TextBlock" and some are new:

(bool) AutoDetectTextFlowDirection: if = [true], the text flow will be automatically detected by unicode characters.

(double) LineBorderIndent: (temp. prop.) used for paragraphs' padding.

(TextAlignmentExtended) TextAlign: extended property for text alignment, now supports "Left", "Right", "Center" and "ByTextFlowDirection" (then text is automatically aligned according to RTL/LTR flow direction); "Justify" will be added later.

(TextFlowDirection) TextFlowDirection: "RightToLeft" or "LeftToRight".

(bool) UseNBidiAlgorithm: if = [true], the text will converted by "NBidi" algorithm, otherwise by mine (can be used with simple texts, works faster then "NBidi").

 

 

 

 

Links to pages with binaries, source code, license, documentation and other stuff:

img_show_props "RtlSupport" project page on Codeplex.com

img_show_props"BidiControls" project page on Codeplex.com (patch is available here).

img_show_props Source code can be downloaded also from here.

PS: I'm not responsible for any damage that may be caused from reading this post or by using binaries, sources or other stuff that is related to this post or my blog. Fill free to use/extend/improve/publish my library with reference to my blog or to my email. Blah, blah, blah...

מי שהאזין לחדשות ביממה האחרונה נוכח לדעת שבחירות הפריימריז שהיו צריכים להתקיים היום במפלגת העבודה בוטלו. על פי הפרסומים בתקשורת סיבת הביטול הנה "שורה של תקלות טכניות"  במערכת המחשוב של חברת "טלדור". לטענת חברת "טלדור" המערכת עבדה באופן תקין בהרצות הפיילוט, העיתונים דווחו על בעיות תקשורת, על מסכי המגע שלא עבדו טוב (כנראה שלא כוילו כראו לכן לא הגיבו נכון למגע, ז"א אם לחצתי על מועמד א' בפועל הלחיצה נרשמה על המועמד ב') ועוד שורה של תקלות.

לפי דעתי הכשל היה צפוי ואם מנהל ה- IT של מפלגת העבודה (אם יש כזה) היה עושה קצת מחקר היה מגלה שניסיון להכניס מערכות הצבעה ממוחחשבות נכשל (או שעבר בצורה מאוד כואבת ולא כדאית מבחינה כלכלית ומנטלית) בהמון מקומות בעולם (למשל בבחירות האחרונות בארה"ב). חברת "טלדור" מצידה זכתה במכרז שמן והצטרפה לרשימת חברות ה- IT שכשלו במשימת המחשוב של הבחירות.

כאחד שמשתייך לצד הנלהב והתומך של מחשוב בכל דבר אומר שלא תמיד כדאי לרוץ עם טכנולוגיות חשדות לפני בחינת כל האפשרויות ועשיית מחקר רציני. בניית מערכת כוללת אשר תומכת בבחירות עסק לגמרי לא פשוט וכל רכיב שגוי יכול להביא לקריסה ולפאניקה. חוץ ממרכיבי התקשורת, ההצפנה, מסדי הנתונים ועוד, יש מרכיב לא פחות חשוב - "ממשק המשתמש", ניסיון להכניס מסכי מגע כמרכיב תקשורת עם מצביע נכשל.

מניסיוני בעבודה מסכי המגע (ויצא לי לעבוד עם מלא דגמים שונים ומשונים) אומר שזה ממשק הפעלה סקסי, אבל לא הכי אמין, לא פעם יצא לי לעזור לאנשים קשישים בבנק בהתמודדות עם מסכי voting_atmהמגע, מסך מגע חייב להיות מכויל היטב, בהרבה פעמים התוכנה מתאפסת וזיהוי הקואורדינטות נעשה באופו שגוי, להמון אנשים (בעיקר אנשים קשישים שאין להם ניסיון עם מחשב) הממשק לא טבעי/איטואיטיבי. מכונות למכירת הרכטיסים בתחנות רכבת סובלות באותן התקלות, וזה רק חלק קטן מבעיות UI שיכולות להתעורר. מוח אנושי מתמודד מצויין עם זיכרון של הפעלת שרירים, ניתן לשחזר פעולה מוטורית עם חפץ מוחשי מכני אשר  Election_for_Dummiesניתן לחוש. לטלפונים סלולריים בעלי מסך מגע ישנה את אותה הבעיה, מי שהתרגל להקיש מספרים ו- SMS-ים באופן עיוור בעזרת מקלדת פיזית של המכשיר יתקשה לבצע את אותה הפעולה על עיוור עם טל' בעל מסך מגע, אפילו פעולה פשוטה כמו מענה/ניתוק מהיר ע"י הקשה על הכפתור הרלבנטי כאשר הטל' בכיס, אינה פשוטה יותר עם המכשיר בעל מסך מגע ונטול כפתורים בסיסיים.

מרכיב ה- UI בנוסף למסך המגע הנו GUI של התוכנה המשמשת להצגת המועמדים, כאן ניתן לומר שיש יתרון עצום על הפתקים הרגילים (אך יעילים). ניתן להציג את תמונת מועמד יחד עם השם (זה מאוד עוזר) ועוד נתונים נוספים שיכולים לסייע בתהליך של ההצבעה.

אני מאוד בעד למחשב את ההליך של הבחירות, לייעל תהליכים ולקצר זמני החישוב של התוצאות, אבל זה חייב להתבצע בשלבים ובנוסף לכלול חקר ישימות וחליפות מעמיק, חייבים לספק ממשק משתמש יעיל, קשיח, בדומה לכספומטים הישנים והטובים עם לחצנים מכניים גדולים (ללא מסכי המגע, מסך רגיל ולא מתוחכם), לפשט, לפשט ועוד פעם לפשט. בשנים האחרונות חלה ירידה דרסתית במוטיבציה של אנשים להזיז את האחוריים שלהם לכוון תחנת הצבעה (לרוב בגלל סיבות פוליטיות ויאוש מהמועמדים), שיבוש התהליך של ההצבעה יביא לתסכול ולירידה נוספת בכמות הבוחרים. השיטה הממושבת תוריד דרסתית טעויות וזיופים ברוב המוקומות, אבל שלא תהיה לכם השליה, הזיופים לא יעלמו גם בשיטה הדיגיטלית, תמיד ניתן למצוא דרך היקפית.
היתרון העצום הוא בסטטיסטיקה, כאן תבוא חגיגה טלויזיונית/תקשורתית, העתונאים יקבלו דווחים כמעט בזמן אמת, גראפים צבעוניים יתעופפו להם על מסכי הענק, פרשנים ינופפו בידיהם מול מסכים וירטואליים באולפנים ססגוניים, דודות וירטואליות יעברו teleporting מאולפן במטולה לאולפן בתל-אביב וערוצים יתפארו מהולוגרמות מזוייפןת, ממש הפנינג בחירות!

נחזור למציאות: יתכן ועלות הכשל של "טלדור" תהיה עצומה, תדמית פגועה, מפגלות תהיינה בחרדה מהטמעה של טכנולוגיה חדשה, מפלגת העבודה בקנטים (לא ברור איך אפשר לסדר בחירות חדשות עד יום חמישי). אני מאחל ל"טלדור" שתצא מהסיפור הזה בריאה ושלמה ושכל התקלות יסודרו בעתיד (עם השינויים הנדרשים), ואולי יתברר שלא היה כאן שום סיפור של כשל וטכנולוגי והכל היה ונשאר עניין פולטי בלבד.

להלן שיעור היום ב"איך UI קשור לכשל של הליך דמוקרטי".

 

PS: אין לי שוב כוונה לפגוע בשום צד, פוסט זה מביע דעה אישית שלי בלבד, אין לראות בכתוב עובדות גמרות, בלה, בלה, בלה, בקיצר אני לא רוצה להיות אחראי לשום מהומה של סילוף דבריי מפוסט זה :)

Posted by Maxim | 4 comment(s)
תגים:, , , ,