Exemplo n.º 1
0
/* ==================================================================== */
BOOL scTextline::TestOffsets( scTextline*				orgTxl,
							  const scStreamChangeInfo& sc )
{
	if ( GetPara() == sc.GetPara() ) {
		if ( GetStartOffset() > sc.GetOffset() )
			return GetStartOffset() - sc.GetLength() == orgTxl->GetStartOffset() &&
				   GetEndOffset() - sc.GetLength()	 == orgTxl->GetEndOffset();
	}	
	return GetStartOffset() == orgTxl->GetStartOffset() && 
		   GetEndOffset()	== orgTxl->GetEndOffset();
}
Exemplo n.º 2
0
bool TessdataManager::OverwriteComponents(
    const char *new_traineddata_filename,
    char **component_filenames,
    int num_new_components) {
  int i;
  inT64 offset_table[TESSDATA_NUM_ENTRIES];
  TessdataType type = TESSDATA_NUM_ENTRIES;
  bool text_file = false;
  FILE *file_ptr[TESSDATA_NUM_ENTRIES];
  for (i = 0; i < TESSDATA_NUM_ENTRIES; ++i) {
    offset_table[i] = -1;
    file_ptr[i] = NULL;
  }
  FILE *output_file = fopen(new_traineddata_filename, "wb");
  if (output_file == NULL) {
    tprintf("Error opening %s for writing\n", new_traineddata_filename);
    return false;
  }

  // Leave some space for recording the offset_table.
  if (fseek(output_file,
            sizeof(inT32) + sizeof(inT64) * TESSDATA_NUM_ENTRIES, SEEK_SET)) {
    fclose(output_file);
    tprintf("Error seeking %s\n", new_traineddata_filename);
    return false;
  }

  // Open the files with the new components.
  for (i = 0; i < num_new_components; ++i) {
    if (TessdataTypeFromFileName(component_filenames[i], &type, &text_file))
      file_ptr[type] = fopen(component_filenames[i], "rb");
  }

  // Write updated data to the output traineddata file.
  for (i = 0; i < TESSDATA_NUM_ENTRIES; ++i) {
    if (file_ptr[i] != NULL) {
      // Get the data from the opened component file.
      offset_table[i] = ftell(output_file);
      CopyFile(file_ptr[i], output_file, kTessdataFileIsText[i], -1);
      fclose(file_ptr[i]);
    } else {
      // Get this data component from the loaded data file.
      if (SeekToStart(static_cast<TessdataType>(i))) {
        offset_table[i] = ftell(output_file);
        CopyFile(data_file_, output_file, kTessdataFileIsText[i],
                 GetEndOffset(static_cast<TessdataType>(i)) -
                 ftell(data_file_) + 1);
      }
    }
  }
  const char *language_data_path_prefix = strchr(new_traineddata_filename, '.');
  return WriteMetadata(offset_table, language_data_path_prefix, output_file);
}
Exemplo n.º 3
0
/* ==================================================================== */
BOOL scTextline::IsLastLinePara ( ) const
{
	BOOL			tf;

	if ( Marked( scINVALID | scREPAINT ) )
		return true;

	scAssertValid( false );

	tf = Marked( scLASTLINE );
	if ( tf ) {
		if ( !fPara->Marked( scREBREAK ) )
			scAssert( GetEndOffset() == PARAChSize( fPara ) );
	}
	return tf;
}
Exemplo n.º 4
0
bool TessdataManager::ExtractToFile(const char *filename) {
  TessdataType type = TESSDATA_NUM_ENTRIES;
  bool text_file = false;
  ASSERT_HOST(tesseract::TessdataManager::TessdataTypeFromFileName(
      filename, &type, &text_file));
  if (!SeekToStart(type)) return false;

  FILE *output_file = fopen(filename, "wb");
  if (output_file == NULL) {
    printf("Error openning %s\n", filename);
    exit(1);
  }
  inT64 begin_offset = ftell(GetDataFilePtr());
  inT64 end_offset = GetEndOffset(type);
  tesseract::TessdataManager::CopyFile(
      GetDataFilePtr(), output_file, text_file,
      end_offset - begin_offset + 1);
  fclose(output_file);
  return true;
}
//************************************************************************************
void CBCGPOutlineParser::DoUpdateOffsets (const CString& strBuffer, 
										  const int nStartOffset, const int nEndOffset, 
										  CObList& lstBlocks)
{
	// Update name offsets, start offsets and end offsets:
	CBCGPOutlineNode* pPreviousNode = NULL;
	CObList lstIgnoreBlocks;
	for (POSITION pos = lstBlocks.GetHeadPosition (); pos != NULL; )
	{
		CBCGPOutlineNode* pNode = (CBCGPOutlineNode*) lstBlocks.GetNext (pos);
		ASSERT_VALID (pNode);

		const BlockType* pBlockType = GetBlockType (pNode->m_nBlockType);
		if (pBlockType != NULL && !pBlockType->m_bIgnore)
		{
			// --------------------------------------
			// Update name offsets and start offsets:
			// --------------------------------------
			CString strName;
			int nSearchTo = nStartOffset;
			if (pPreviousNode != NULL && 
				pPreviousNode->m_nEnd < pNode->m_nStart &&
				pPreviousNode->m_nEnd > nStartOffset)
			{
				nSearchTo = pPreviousNode->m_nEnd;
			}
			pNode->m_nNameOffset = GetNameOffset (strBuffer, pNode->m_nStart, nSearchTo,
												  pBlockType, lstIgnoreBlocks, strName);
			int nNewStart = GetStartOffset (strBuffer, pNode->m_nStart, pNode->m_nStart - pNode->m_nNameOffset, lstIgnoreBlocks);
			ASSERT (nNewStart >= nSearchTo);

			int nDelta = nNewStart - pNode->m_nStart;
			pNode->m_nNameOffset += nDelta;
			pNode->m_nStart = nNewStart;
			// strName = strName.Left (strName.GetLength () + nDelta);
			// pNode->m_strName = strName;

			// -------------------
			// Update end offsets:
			// -------------------
			nSearchTo = nEndOffset;
			if (pos != NULL)
			{
				CBCGPOutlineNode* pNextNode = (CBCGPOutlineNode*) lstBlocks.GetAt (pos);
				ASSERT_VALID (pNextNode);

				if (pNextNode->m_nStart > pNode->m_nEnd &&
					pNextNode->m_nStart < nEndOffset)
				{
					nSearchTo = pNextNode->m_nStart;
				}
			}
			int nNewEnd = GetEndOffset (strBuffer, pNode->m_nEnd, nSearchTo);
			ASSERT (nNewEnd <= nSearchTo);
			pNode->m_nEnd = nNewEnd;

			pPreviousNode = pNode;
			lstIgnoreBlocks.AddTail (pNode);
		}
		else
		{
			lstIgnoreBlocks.AddTail (pNode);
		}
	}
}
Exemplo n.º 6
0
/* reposition the line, this line is part of a flex column and it may
 * need repositioning depending on the line rag
 * returns the next line - thus optimizing loop in column a little
 */
void scTextline::Reposition( MicroPoint measure )
{
	MicroPoint	displacement;
	CharRecordP chP;
	scFlowDir	flowDir;
	scMuPoint	transPt( fOrigin );

	flowDir = fColumn->GetFlowdir( );
	
	if ( flowDir.IsHorizontal() ) {
		transPt.x = -transPt.x;
		transPt.y = 0;
	}
	else {
		transPt.x = 0;
		transPt.y = -transPt.y;
	}

	switch ( GetFlexLineAdjustment() &	eRagFlag ) {
		case eRagLeft:
			fOrigin.Translate( transPt );
			fInkExtents.Translate( transPt );
				
			displacement	= measure - fLength;
			if ( flowDir.IsHorizontal() ) {
				fOrigin.Translate( displacement, 0 );
				fInkExtents.Translate( displacement, 0 );
			}
			else {
				fOrigin.Translate( 0, displacement );
				fInkExtents.Translate( 0, displacement );
			}
			break;
			
		case eRagCentered:
			fOrigin.Translate( transPt );
			fInkExtents.Translate( transPt );
		
			displacement	= ( measure - fLength ) / 2;
			if ( flowDir.IsHorizontal() ) {
				fOrigin.Translate( displacement, 0 );
				fInkExtents.Translate( displacement, 0 );
			}
			else {
				fOrigin.Translate( 0, displacement );
				fInkExtents.Translate( 0, displacement );
			}
			break;

		case eRagJustified:
			if ( !Marked( scLASTLINE ) || GetFlexLineAdjustment() & eLastLineJust ) {
				chP = (CharRecordP)GetPara()->GetCharArray().Lock();
				if ( BRKJustify( chP, GetStartOffset(), GetEndOffset(), measure ) )
					Mark( scREPAINT );

				if ( flowDir.IsHorizontal() )
					fInkExtents.x2	= fInkExtents.x1 + measure + fInkExtents.Depth() / 2;
				else 
					fInkExtents.y2	= fInkExtents.y1 + measure + fInkExtents.Width() / 2;
				fLength 	= measure;
				GetPara()->GetCharArray().Unlock();
			}
			break;
		
		case eRagRight:
			break;
	}
}