File size: 3,477 Bytes
93c4f75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
def text_to_unicode_braille(braille_text):
    """
    Convert Braille dots notation to Unicode Braille symbols.
    
    Args:
        braille_text: Braille text in dots notation
        
    Returns:
        Text with Unicode Braille symbols
    """
    # Mapping from Braille dots to Unicode Braille patterns
    # Unicode Braille patterns start at U+2800 (⠀)
    unicode_base = 0x2800
    
    # Convert each Braille character to its Unicode equivalent
    unicode_braille = ""
    for char in braille_text:
        # Check if the character is a standard Braille pattern
        if char in "⠀⠁⠂⠃⠄⠅⠆⠇⠈⠉⠊⠋⠌⠍⠎⠏⠐⠑⠒⠓⠔⠕⠖⠗⠘⠙⠚⠛⠜⠝⠞⠟⠠⠡⠢⠣⠤⠥⠦⠧⠨⠩⠪⠫⠬⠭⠮⠯⠰⠱⠲⠳⠴⠵⠶⠷⠸⠹⠺⠻⠼⠽⠾⠿":
            unicode_braille += char
        else:
            # For non-Braille characters, keep them as is
            unicode_braille += char
    
    return unicode_braille

def create_braille_html(braille_text):
    """
    Create HTML to display Braille with proper styling.
    
    Args:
        braille_text: Braille text (either in dots or Unicode)
        
    Returns:
        HTML string for displaying Braille
    """
    # Convert to Unicode Braille if not already
    unicode_braille = text_to_unicode_braille(braille_text)
    
    # Replace newlines with <br> tags before using in f-string
    formatted_text = unicode_braille.replace('\n', '<br>')
    
    # Create HTML with proper styling
    html = f"""
    <div style="font-family: 'Courier New', monospace; font-size: 20px; line-height: 1.5; 
                background-color: #f5f5f5; padding: 15px; border-radius: 5px;">
        {formatted_text}
    </div>
    """
    
    return html


def create_braille_comparison(text, braille_text):
    """
    Create a side-by-side comparison of text and its Braille representation.
    
    Args:
        text: Original text
        braille_text: Braille translation
        
    Returns:
        HTML string for displaying the comparison
    """
    # Convert to Unicode Braille
    unicode_braille = text_to_unicode_braille(braille_text)
    
    # Split into lines
    text_lines = text.split('\n')
    braille_lines = unicode_braille.split('\n')
    
    # Ensure both lists have the same length
    max_lines = max(len(text_lines), len(braille_lines))
    text_lines = text_lines + [''] * (max_lines - len(text_lines))
    braille_lines = braille_lines + [''] * (max_lines - len(braille_lines))
    
    # Create HTML table for comparison
    html = """
    <style>
        .braille-table {
            width: 100%;
            border-collapse: collapse;
        }
        .braille-table td {
            padding: 8px;
            vertical-align: top;
            border-bottom: 1px solid #ddd;
        }
        .braille-text {
            font-family: 'Courier New', monospace;
            font-size: 20px;
            background-color: #f5f5f5;
        }
        .original-text {
            font-family: Arial, sans-serif;
        }
    </style>
    <table class="braille-table">
        <tr>
            <th>Original Text</th>
            <th>Braille Representation</th>
        </tr>
    """
    
    for i in range(max_lines):
        html += f"""
        <tr>
            <td class="original-text">{text_lines[i]}</td>
            <td class="braille-text">{braille_lines[i]}</td>
        </tr>
        """
    
    html += "</table>"
    
    return html