Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(347)

Side by Side Diff: third_party/liblouis/nacl_wrapper/liblouis_wrapper.cc

Issue 2954413003: Support rich line output in both speech and braille (Closed)
Patch Set: Fix browser test Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 Google Inc. 1 // Copyright 2013 Google Inc.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of 4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at 5 // the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 int out_cursor_position; 133 int out_cursor_position;
134 int* out_cursor_position_ptr; 134 int* out_cursor_position_ptr;
135 if (params.cursor_position < 0) { 135 if (params.cursor_position < 0) {
136 out_cursor_position = -1; 136 out_cursor_position = -1;
137 out_cursor_position_ptr = NULL; 137 out_cursor_position_ptr = NULL;
138 } else { 138 } else {
139 out_cursor_position = params.cursor_position; 139 out_cursor_position = params.cursor_position;
140 out_cursor_position_ptr = &out_cursor_position; 140 out_cursor_position_ptr = &out_cursor_position;
141 } 141 }
142 142
143 std::vector<unsigned char> form_type_map(params.form_type_map);
144
143 // Invoke liblouis. Do this in a loop since we can't precalculate the 145 // Invoke liblouis. Do this in a loop since we can't precalculate the
144 // translated size. We add an extra slot in the output buffer so that 146 // translated size. We add an extra slot in the output buffer so that
145 // common cases like single digits or capital letters won't always trigger 147 // common cases like single digits or capital letters won't always trigger
146 // retranslations (see the comments above the second exit condition inside 148 // retranslations (see the comments above the second exit condition inside
147 // the loop). We also set an arbitrary upper bound for the allocation 149 // the loop). We also set an arbitrary upper bound for the allocation
148 // to make sure the loop exits without running out of memory. 150 // to make sure the loop exits without running out of memory.
149 for (int outalloc = (inbufsize + 1) * 2, maxoutalloc = (inbufsize + 1) * 8; 151 for (int outalloc = (inbufsize + 1) * 2, maxoutalloc = (inbufsize + 1) * 8;
150 outalloc <= maxoutalloc; outalloc *= 2) { 152 outalloc <= maxoutalloc; outalloc *= 2) {
151 int inlen = inbufsize; 153 int inlen = inbufsize;
152 outlen = outalloc; 154 outlen = outalloc;
153 outbuf.resize(outalloc); 155 outbuf.resize(outalloc);
154 braille_to_text.resize(outalloc); 156 braille_to_text.resize(outalloc);
155 int result = lou_translate(params.table_names.c_str(), 157 form_type_map.resize(outalloc);
156 &inbuf[0], &inlen, &outbuf[0], &outlen, 158 int result = lou_translate(
157 NULL /* typeform */, NULL /* spacing */, 159 params.table_names.c_str(), &inbuf[0], &inlen, &outbuf[0], &outlen,
158 &text_to_braille[0], &braille_to_text[0], 160 &form_type_map[0], NULL /* spacing */, &text_to_braille[0],
159 out_cursor_position_ptr, dotsIO /* mode */); 161 &braille_to_text[0], out_cursor_position_ptr, dotsIO /* mode */);
160 if (result == 0) { 162 if (result == 0) {
161 // TODO(jbroman): log this 163 // TODO(jbroman): log this
162 return false; 164 return false;
163 } 165 }
164 // If all of inbuf was not consumed, the output buffer must be too small 166 // If all of inbuf was not consumed, the output buffer must be too small
165 // and we have to retry with a larger buffer. 167 // and we have to retry with a larger buffer.
166 // In addition, if all of outbuf was exhausted, there's no way to know if 168 // In addition, if all of outbuf was exhausted, there's no way to know if
167 // more space was needed, so we'll have to retry the translation in that 169 // more space was needed, so we'll have to retry the translation in that
168 // corner case as well. 170 // corner case as well.
169 if (inlen == inbufsize && outlen < outalloc) 171 if (inlen == inbufsize && outlen < outalloc)
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 // TODO(jbroman): log this 241 // TODO(jbroman): log this
240 return false; 242 return false;
241 } 243 }
242 244
243 // Return the back translation result. 245 // Return the back translation result.
244 out->swap(text); 246 out->swap(text);
245 return true; 247 return true;
246 } 248 }
247 249
248 } // namespace liblouis_nacl 250 } // namespace liblouis_nacl
OLDNEW
« no previous file with comments | « third_party/liblouis/nacl_wrapper/liblouis_instance.cc ('k') | third_party/liblouis/nacl_wrapper/translation_params.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698