returns a char sample corresponding to the bitmap between 2 seg pts
| 144 | |
| 145 | // returns a char sample corresponding to the bitmap between 2 seg pts |
| 146 | CharSamp *CubeSearchObject::CharSample(int start_pt, int end_pt) { |
| 147 | // init if necessary |
| 148 | if (!init_ && !Init()) |
| 149 | return NULL; |
| 150 | // validate segment range |
| 151 | if (!IsValidSegmentRange(start_pt, end_pt)) |
| 152 | return NULL; |
| 153 | |
| 154 | // look for the samp in the cache |
| 155 | if (samp_cache_ && samp_cache_[start_pt + 1] && |
| 156 | samp_cache_[start_pt + 1][end_pt]) { |
| 157 | return samp_cache_[start_pt + 1][end_pt]; |
| 158 | } |
| 159 | // create a char samp object from the specified range of segments |
| 160 | bool left_most; |
| 161 | bool right_most; |
| 162 | CharSamp *samp = CharSamp::FromConComps(segments_, start_pt + 1, |
| 163 | end_pt - start_pt, NULL, |
| 164 | &left_most, &right_most, hgt_); |
| 165 | if (!samp) |
| 166 | return NULL; |
| 167 | |
| 168 | if (kUseCroppedChars) { |
| 169 | CharSamp *cropped_samp = samp->Crop(); |
| 170 | // we no longer need the orig sample |
| 171 | delete samp; |
| 172 | if (!cropped_samp) |
| 173 | return NULL; |
| 174 | samp = cropped_samp; |
| 175 | } |
| 176 | |
| 177 | // get the dimensions of the new cropped sample |
| 178 | int char_top = samp->Top(); |
| 179 | int char_wid = samp->Width(); |
| 180 | int char_hgt = samp->Height(); |
| 181 | |
| 182 | // for cursive languages, these features correspond to whether |
| 183 | // the charsamp is at the beginning or end of conncomp |
| 184 | if (cntxt_->Cursive() == true) { |
| 185 | // first and last char flags depend on reading order |
| 186 | bool first_char = rtl_ ? right_most : left_most; |
| 187 | bool last_char = rtl_ ? left_most : right_most; |
| 188 | |
| 189 | samp->SetFirstChar(first_char ? 255 : 0); |
| 190 | samp->SetLastChar(last_char ? 255 : 0); |
| 191 | } else { |
| 192 | // for non cursive languages, these features correspond |
| 193 | // to whether the charsamp is at the beginning or end of the word |
| 194 | samp->SetFirstChar((start_pt == -1) ? 255 : 0); |
| 195 | samp->SetLastChar((end_pt == (segment_cnt_ - 1)) ? 255 : 0); |
| 196 | } |
| 197 | samp->SetNormTop(255 * char_top / hgt_); |
| 198 | samp->SetNormBottom(255 * (char_top + char_hgt) / hgt_); |
| 199 | samp->SetNormAspectRatio(255 * char_wid / (char_wid + char_hgt)); |
| 200 | |
| 201 | // add to cache & return |
| 202 | samp_cache_[start_pt + 1][end_pt] = samp; |
| 203 | return samp; |
no test coverage detected