Example #1
0
void OcrGocrDialog::slotWriteConfig( void )
{
    kDebug();

    OcrBaseDialog::slotWriteConfig();

    KConfigGroup grp1 = KGlobal::config()->group(CFG_GROUP_OCR_DIA);
    grp1.writePathEntry(CFG_GOCR_BINARY, getOCRCmd());

    KConfigGroup grp2 = KGlobal::config()->group(CFG_GROUP_GOCR);
    grp2.writeEntry(CFG_GOCR_GRAYLEVEL, getGraylevel());
    grp2.writeEntry(CFG_GOCR_DUSTSIZE, getDustsize());
    grp2.writeEntry(CFG_GOCR_SPACEWIDTH, getSpaceWidth());
}
Example #2
0
void LineBreaker::computeBreaksOptimal(bool isRectangle) {
  size_t active = 0;
  size_t nCand = mCandidates.size();
  float width = mLineWidths.getLineWidth(0);
  float shortLineFactor = mJustified ? 0.75f : 0.5f;
  float maxShrink = mJustified ? SHRINKABILITY * getSpaceWidth() : 0.0f;

  // "i" iterates through candidates for the end of the line.
  for (size_t i = 1; i < nCand; i++) {
    bool atEnd = i == nCand - 1;
    float best = SCORE_INFTY;
    size_t bestPrev = 0;
    size_t lineNumberLast = 0;

    if (!isRectangle) {
      size_t lineNumberLast = mCandidates[active].lineNumber;
      width = mLineWidths.getLineWidth(lineNumberLast);
    }
    ParaWidth leftEdge = mCandidates[i].postBreak - width;
    float bestHope = 0;

    // "j" iterates through candidates for the beginning of the line.
    for (size_t j = active; j < i; j++) {
      if (!isRectangle) {
        size_t lineNumber = mCandidates[j].lineNumber;
        if (lineNumber != lineNumberLast) {
          float widthNew = mLineWidths.getLineWidth(lineNumber);
          if (widthNew != width) {
            leftEdge = mCandidates[i].postBreak - width;
            bestHope = 0;
            width = widthNew;
          }
          lineNumberLast = lineNumber;
        }
      }
      float jScore = mCandidates[j].score;
      if (jScore + bestHope >= best)
        continue;
      float delta = mCandidates[j].preBreak - leftEdge;

      // compute width score for line

      // Note: the "bestHope" optimization makes the assumption that, when delta
      // is non-negative, widthScore will increase monotonically as successive
      // candidate breaks are considered.
      float widthScore = 0.0f;
      float additionalPenalty = 0.0f;
      if ((atEnd || !mJustified) && delta < 0) {
        widthScore = SCORE_OVERFULL;
      } else if (atEnd && mStrategy != kBreakStrategy_Balanced) {
        // increase penalty for hyphen on last line
        additionalPenalty =
            LAST_LINE_PENALTY_MULTIPLIER * mCandidates[j].penalty;
        // Penalize very short (< 1 - shortLineFactor of total width) lines.
        float underfill = delta - shortLineFactor * width;
        widthScore = underfill > 0 ? underfill * underfill : 0;
      } else {
        widthScore = delta * delta;
        if (delta < 0) {
          if (-delta < maxShrink * (mCandidates[i].postSpaceCount -
                                    mCandidates[j].preSpaceCount)) {
            widthScore *= SHRINK_PENALTY_MULTIPLIER;
          } else {
            widthScore = SCORE_OVERFULL;
          }
        }
      }

      if (delta < 0) {
        active = j + 1;
      } else {
        bestHope = widthScore;
      }

      float score = jScore + widthScore + additionalPenalty;
      if (score <= best) {
        best = score;
        bestPrev = j;
      }
    }
    mCandidates[i].score = best + mCandidates[i].penalty + mLinePenalty;
    mCandidates[i].prev = bestPrev;
    mCandidates[i].lineNumber = mCandidates[bestPrev].lineNumber + 1;
#if VERBOSE_DEBUG
    ALOGD("break %zd: score=%g, prev=%zd", i, mCandidates[i].score,
          mCandidates[i].prev);
#endif
  }
  finishBreaksOptimal();
}