Ejemplo n.º 1
0
CFX_WideString CRF_TextPage::GetPageText(int start, int nCount ) const
{
    if(nCount == -1) {
        nCount = CountChars();
        start = 0;
    } else if(nCount < 1) {
        return L"";
    } else if(start >= CountChars()) {
        return L"";
    }
    int i, index = start + nCount;
    FPDF_CHAR_INFO info;
    CFX_WideString str;
    CFX_FloatRect recttmp;
    FX_BOOL bstart = TRUE;
    for(i = start; i < index; i++) {
        GetCharInfo(i, info);
        if(bstart) {
            recttmp = info.m_CharBox;
            str += info.m_Unicode;
            bstart = FALSE;
        } else if (_IsInsameline(recttmp, info.m_CharBox)) {
            str += info.m_Unicode;
        } else {
            str += L"\r\n";
            recttmp = info.m_CharBox;
            str += info.m_Unicode;
        }
    }
    if(str.IsEmpty()) {
        return L"";
    }
    return str;
}
Ejemplo n.º 2
0
CFX_WideString CRF_TextPage::GetTextByRect(CFX_FloatRect rect) const
{
    int count;
    FPDF_CHAR_INFO info;
    CFX_WideString str;
    CFX_FloatRect  Recttmp;
    FX_BOOL bstart = TRUE;
    count = CountChars();
    if(rect.IsEmpty()) {
        return L"";
    }
    for(int i = 0; i < count; i++) {
        GetCharInfo(i, info);
        if(_IsIntersect(rect, info.m_CharBox)) {
            if(bstart) {
                Recttmp = info.m_CharBox;
                str += info.m_Unicode;
                bstart = FALSE;
            } else if(_IsInsameline(Recttmp, info.m_CharBox)) {
                str += info.m_Unicode;
            } else {
                str += L"\r\n";
                Recttmp = info.m_CharBox;
                str += info.m_Unicode;
            }
        }
    }
    if(str.IsEmpty()) {
        return L"";
    } else {
        return str;
    }
}
Ejemplo n.º 3
0
void CRF_TextPage::GetRectsArrayByRect(CFX_FloatRect rect, CFX_RectArray& resRectArray) const
{
    int count, i;
    FX_BOOL bstart = TRUE;
    FPDF_CHAR_INFO info;
    CFX_FloatRect recttmp;
    count = CountChars();
    for(i = 0; i < count; i++) {
        GetCharInfo(i, info);
        if(_IsIntersect(rect, info.m_CharBox)) {
            if(bstart) {
                recttmp = info.m_CharBox;
                bstart = FALSE;
            } else if(_IsInsameline(recttmp, info.m_CharBox)) {
                recttmp.right = info.m_CharBox.right;
                if(info.m_CharBox.top > recttmp.top) {
                    recttmp.top = info.m_CharBox.top;
                }
                if(info.m_CharBox.bottom < recttmp.bottom) {
                    recttmp.bottom = info.m_CharBox.bottom;
                }
            } else {
                resRectArray.Add(recttmp);
                recttmp = info.m_CharBox;
            }
        }
    }
    resRectArray.Add(recttmp);
}
Ejemplo n.º 4
0
int CRF_TextPage::GetIndexAtPos(CPDF_Point point, FX_FLOAT xTorelance, FX_FLOAT yTorelance) const
{
    int index = -1, i = 0, j = 0;
    FPDF_CHAR_INFO info;
    CFX_FloatRect rectTmp;
    FX_FLOAT MinDistance = 1000, DistanceTmp = 0;
    FX_FLOAT rect_bottom = point.x - xTorelance;
    CFX_FloatRect TorelanceRect(rect_bottom <= 0 ? 0 : rect_bottom, point.y - yTorelance, point.x + xTorelance, point.y + yTorelance);
    int count = CountChars();
    for(i = 0; i < count; i++) {
        GetCharInfo(i, info);
        rectTmp = info.m_CharBox;
        if(rectTmp.Contains(point.x, point.y)) {
            index = i;
            break;
        } else if(_IsIntersect(rectTmp, TorelanceRect)) {
            DistanceTmp = _GetDistance(rectTmp, point);
            if(DistanceTmp < MinDistance) {
                MinDistance = DistanceTmp;
                index = i;
            }
        }
    }
    return index;
}
Ejemplo n.º 5
0
CString QuoteSpaces(const CString& FilePathName, const int QuoteMode)
{
 CString result = FilePathName;
 if ((2==QuoteMode) || (CountChars(FilePathName,' ')>0))
 {
  result = QuoteStr(FilePathName);
 }
 return result;
}
Ejemplo n.º 6
0
WideString CPDF_TextPage::GetPageText(int start, int count) const {
  if (start < 0 || start >= CountChars() || count <= 0 || !m_bIsParsed ||
      m_CharList.empty() || m_TextBuf.GetLength() == 0) {
    return WideString();
  }

  const int count_chars = CountChars();
  int text_start = TextIndexFromCharIndex(start);

  // If the character at |start| is a non-printing character, then
  // TextIndexFromCharIndex will return -1, so scan ahead to the first printing
  // character.
  while (text_start < 0) {
    if (start >= count_chars)
      return WideString();
    start++;
    text_start = TextIndexFromCharIndex(start);
  }

  count = std::min(count, count_chars - start);

  int last = start + count - 1;
  int text_last = TextIndexFromCharIndex(last);

  // If the character at |last| is a non-printing character, then
  // TextIndexFromCharIndex will return -1, so scan back to the last printing
  // character.
  while (text_last < 0) {
    if (last < text_start)
      return WideString();

    last--;
    text_last = TextIndexFromCharIndex(last);
  }

  if (text_last < text_start)
    return WideString();

  int text_count = text_last - text_start + 1;

  return WideString(m_TextBuf.AsStringView().Mid(
      static_cast<size_t>(text_start), static_cast<size_t>(text_count)));
}
Ejemplo n.º 7
0
	//--------------------------------------------------------------------------------
	CUTF16String& CUTF16String::Remove( unsigned short usPos, unsigned short usCount )
	{
		CUTF16Char Begin = CharAt( usPos );
		CUTF16Char End = CharAt( usPos + usCount );

		m_String.Remove( static_cast< unsigned short >( Begin.ptr() - m_String.GetBuffer() ), static_cast< unsigned short >( End.ptr() - Begin.ptr() ) );
		m_String.ReleaseBuffer();
		CountChars();
		return *this;
	}
Ejemplo n.º 8
0
	//--------------------------------------------------------------------------------
	CUTF16String& CUTF16String::Insert(  unsigned short usPos, CUTF16String& Src )
	{
		if( usPos > m_usCharCount )
		{
			usPos = m_usCharCount;
		}
		CUTF16Char Ref = CharAt( usPos );
		m_String.Insert( static_cast< unsigned short >( Ref.ptr() - m_String.GetBuffer() ), Src.m_String );
		m_String.ReleaseBuffer();
		CountChars();
		return *this;
	}
Ejemplo n.º 9
0
std::vector<CFX_FloatRect> CPDF_TextPage::GetRectArray(int start,
                                                       int nCount) const {
  std::vector<CFX_FloatRect> rects;
  if (start < 0 || nCount == 0 || !m_bIsParsed)
    return rects;

  const int nCharListSize = CountChars();
  if (start >= nCharListSize)
    return rects;

  if (nCount < 0 || start + nCount > nCharListSize)
    nCount = nCharListSize - start;
  ASSERT(nCount > 0);

  CPDF_TextObject* pCurObj = nullptr;
  CFX_FloatRect rect;
  int curPos = start;
  bool bFlagNewRect = true;
  while (nCount--) {
    PAGECHAR_INFO info_curchar = m_CharList[curPos++];
    if (info_curchar.m_Flag == FPDFTEXT_CHAR_GENERATED)
      continue;
    if (info_curchar.m_CharBox.Width() < kSizeEpsilon ||
        info_curchar.m_CharBox.Height() < kSizeEpsilon) {
      continue;
    }
    if (!pCurObj)
      pCurObj = info_curchar.m_pTextObj.Get();
    if (pCurObj != info_curchar.m_pTextObj) {
      rects.push_back(rect);
      pCurObj = info_curchar.m_pTextObj.Get();
      bFlagNewRect = true;
    }
    if (bFlagNewRect) {
      bFlagNewRect = false;
      rect = info_curchar.m_CharBox;
      rect.Normalize();
      continue;
    }
    info_curchar.m_CharBox.Normalize();
    rect.left = std::min(rect.left, info_curchar.m_CharBox.left);
    rect.right = std::max(rect.right, info_curchar.m_CharBox.right);
    rect.top = std::max(rect.top, info_curchar.m_CharBox.top);
    rect.bottom = std::min(rect.bottom, info_curchar.m_CharBox.bottom);
  }
  rects.push_back(rect);
  return rects;
}
Ejemplo n.º 10
0
int CRF_TextPage::CountBoundedSegments(FX_FLOAT left, FX_FLOAT top, FX_FLOAT right, FX_FLOAT bottom, FX_BOOL bContains)
{
    if (!m_CountBSArray) {
        return -1;
    }
    m_CountBSArray->RemoveAll();
    CFX_FloatRect floatrect(left, bottom, right, top);
    int totalcount, i, j = 0, counttmp = 0;
    FX_BOOL bstart = TRUE;
    FPDF_CHAR_INFO info;
    CFX_FloatRect recttmp;
    totalcount = CountChars();
    for(i = 0; i < totalcount; i++) {
        GetCharInfo(i, info);
        if(_IsIntersect(floatrect, info.m_CharBox)) {
            if(bstart) {
                m_CountBSArray->Add(i);
                counttmp = 1;
                recttmp = info.m_CharBox;
                bstart = FALSE;
            } else if(_IsInsameline(recttmp, info.m_CharBox)) {
                recttmp.right = info.m_CharBox.right;
                if(info.m_CharBox.top > recttmp.top) {
                    recttmp.top = info.m_CharBox.top;
                }
                if(info.m_CharBox.bottom < recttmp.bottom) {
                    recttmp.bottom = info.m_CharBox.bottom;
                }
                counttmp ++;
            } else {
                m_CountBSArray->Add(counttmp);
                m_CountBSArray->Add(i);
                counttmp = 1;
                j++;
                recttmp = info.m_CharBox;
            }
        }
    }
    m_CountBSArray->Add(counttmp);
    j++;
    return j;
}
Ejemplo n.º 11
0
BString&
BString::ReplaceCharsSet(const char* setOfChars, const char* with)
{
	if (!setOfChars || !with)
		return *this;

	int32 setCharCount = UTF8CountChars(setOfChars, -1);
	if ((uint32)setCharCount == strlen(setOfChars)) {
		// no multi-byte chars at all
		return ReplaceSet(setOfChars, with);
	}

	BString setString(setOfChars);
	BString result;

	int32 withLength = strlen(with);
	int32 charCount = CountChars();
	for (int32 i = 0; i < charCount; i++) {
		int32 charLength;
		const char* sourceChar = CharAt(i, &charLength);
		bool match = false;

		for (int32 j = 0; j < setCharCount; j++) {
			int32 setCharLength;
			const char* setChar = setString.CharAt(j, &setCharLength);
			if (charLength == setCharLength
				&& memcmp(sourceChar, setChar, charLength) == 0) {
				match = true;
				break;
			}
		}

		if (match)
			result.Append(with, withLength);
		else
			result.Append(sourceChar, charLength);
	}

	*this = result;
	return *this;
}
Ejemplo n.º 12
0
int CPDF_TextPage::GetIndexAtPos(const CFX_PointF& point,
                                 const CFX_SizeF& tolerance) const {
  if (!m_bIsParsed)
    return -3;

  int pos;
  int NearPos = -1;
  double xdif = 5000;
  double ydif = 5000;
  const int nCount = CountChars();
  for (pos = 0; pos < nCount; ++pos) {
    PAGECHAR_INFO charinfo = m_CharList[pos];
    CFX_FloatRect charrect = charinfo.m_CharBox;
    if (charrect.Contains(point))
      break;

    if (tolerance.width <= 0 && tolerance.height <= 0)
      continue;

    CFX_FloatRect charRectExt;
    charrect.Normalize();
    charRectExt.left = charrect.left - tolerance.width / 2;
    charRectExt.right = charrect.right + tolerance.width / 2;
    charRectExt.top = charrect.top + tolerance.height / 2;
    charRectExt.bottom = charrect.bottom - tolerance.height / 2;
    if (!charRectExt.Contains(point))
      continue;

    double curXdif =
        std::min(fabs(point.x - charrect.left), fabs(point.x - charrect.right));
    double curYdif =
        std::min(fabs(point.y - charrect.bottom), fabs(point.y - charrect.top));
    if (curYdif + curXdif < xdif + ydif) {
      ydif = curYdif;
      xdif = curXdif;
      NearPos = pos;
    }
  }
  return pos < nCount ? pos : NearPos;
}
Ejemplo n.º 13
0
void CPDF_TextPage::ParseTextPage() {
  m_bIsParsed = false;
  m_TextBuf.Clear();
  m_CharList.clear();
  m_pPreTextObj = nullptr;
  ProcessObject();

  m_bIsParsed = true;
  m_CharIndex.clear();
  const int nCount = CountChars();
  if (nCount)
    m_CharIndex.push_back(0);

  for (int i = 0; i < nCount; ++i) {
    int indexSize = pdfium::CollectionSize<int>(m_CharIndex);
    const PAGECHAR_INFO& charinfo = m_CharList[i];
    if (charinfo.m_Flag == FPDFTEXT_CHAR_GENERATED ||
        (charinfo.m_Unicode != 0 && !IsControlChar(charinfo)) ||
        (charinfo.m_Unicode == 0 && charinfo.m_CharCode != 0)) {
      if (indexSize % 2) {
        m_CharIndex.push_back(1);
      } else {
        if (indexSize <= 0)
          continue;
        m_CharIndex[indexSize - 1] += 1;
      }
    } else {
      if (indexSize % 2) {
        if (indexSize <= 0)
          continue;
        m_CharIndex[indexSize - 1] = i + 1;
      } else {
        m_CharIndex.push_back(i + 1);
      }
    }
  }
  int indexSize = pdfium::CollectionSize<int>(m_CharIndex);
  if (indexSize % 2)
    m_CharIndex.erase(m_CharIndex.begin() + indexSize - 1);
}
Ejemplo n.º 14
0
void CRF_TextPage::GetCharInfo(int index, FPDF_CHAR_INFO & info) const
{
    if(index >= CountChars() || index < 0 || !m_pDataList) {
        return;
    }
    CRF_CharData* pData = (*m_pDataList)[index];
    FX_FLOAT ReltiveCorddDs = pData->m_pCharState->m_fDescent;
    FX_FLOAT ReltiveCorddAs = pData->m_pCharState->m_fAscent;
    info.m_Flag		= CHAR_NORMAL;
    info.m_pTextObj	= pData->m_pCharState->m_pTextObj;
    info.m_OriginX	= pData->m_PosX;
    info.m_OriginY	= pData->m_PosY - ReltiveCorddDs;
    info.m_FontSize	= pData->m_pCharState->m_fFontSize;
    CFX_FloatRect FloatRectTmp(pData->m_PosX, pData->m_PosY, pData->m_PosX + pData->m_Width, pData->m_PosY + ReltiveCorddAs - ReltiveCorddDs);
    info.m_CharBox	= FloatRectTmp;
    CFX_WideString str = pData->m_pCharState->m_pFont->UnicodeFromCharCode(pData->m_CharCode);
    if(!str.IsEmpty()) {
        info.m_Unicode	= str.GetAt(0);
    } else {
        info.m_Unicode = -1;
    }
    info.m_Charcode = (FX_WCHAR)pData->m_CharCode;
    info.m_Matrix = CFX_Matrix(1, 0, 0, 1, 0, 0);
}
Ejemplo n.º 15
0
	//--------------------------------------------------------------------------------
	CUTF16String::CUTF16String( CChar16 c ) : m_String( c )
	{
		m_String.SetCodePage( CCodePage::eUTF8 );
		CountChars();
	}
Ejemplo n.º 16
0
    //--------------------------------------------------------------------------------
    CUTF16String::CUTF16String( const CChar16* cpString, unsigned short usSrcLen, unsigned short usInitialBufferSize ) : m_String( cpString, usSrcLen, usInitialBufferSize )
    {
		m_String.SetCodePage( CCodePage::eUTF8 );
		CountChars();
    }
Ejemplo n.º 17
0
	//--------------------------------------------------------------------------------
    CUTF16String::CUTF16String( const CChar16* cpString, unsigned short usSrcLen ) : m_String( cpString, usSrcLen )
    {
		m_String.SetCodePage( CCodePage::eUTF8 );
		CountChars();
    }
Ejemplo n.º 18
0
	//--------------------------------------------------------------------------------
    CUTF16String& CUTF16String::Append( const CChar16* cpString, unsigned short usSrcLen )
    {
		m_String.Append( cpString, usSrcLen );
		CountChars();
        return *this;
    }
Ejemplo n.º 19
0
	//--------------------------------------------------------------------------------
	CUTF16String& CUTF16String::operator = ( CChar16 c )
	{
		operator = ( CTString< CChar16, CDefaultSource >( c ) );
		CountChars();
		return *this;
	}
Ejemplo n.º 20
0
    //--------------------------------------------------------------------------------
    CUTF16String::CUTF16String( nsCodeQOR::CTLRef< CChar16 > Src ) : m_String( Src )
    {
		m_String.SetCodePage( CCodePage::eUTF8 );
		CountChars();
    }
Ejemplo n.º 21
0
int main(int argc, char **argv) {

	GetStatisticTable(); /* Wahrscheinlichkeiten einlesen */
	GetFile(); /* zu bearbeitendes File einlesen */

	/*****************  Aufgabe  *****************/

	int periode = 1, r, i, j, sumCounts, flag = 0, offset = 0;
	int h[NUMCHARS]; //h[0] ist die Zahl 'A',h[1] ist die Zahl 'B' usw.
	char schluessel[MaxFileLen], klartexts[MaxFileLen]; //Schlüssel
	double curPro, nxt5Pro, nxt6Pro, max;
	double indexC = 0, tempIndexC = 0;

//zuerst berechnen indexC=sum(PropTable[i]²)
	for (i = 0; i < NUMCHARS; ++i)
		indexC += PropTable[i] * PropTable[i];

// anhand der verschiedenen Schlüsselsleange wird indexC jedesmal berechnet
// falls flag==1 bleibend, dann wir haben die richtige Laenge gefunden
	while (periode < TextLength && flag == 0) {
		flag = 1;
		for (i = 0; i < periode; i++) {
			sumCounts = 0;
			CountChars(i, periode, h);
			for (j = 0; j < NUMCHARS; j++)
				sumCounts += h[j]; //gesamte chars in Leange periode

			tempIndexC = 0;
			for (j = 0; j < NUMCHARS; j++) {
				curPro = h[j] / (double) sumCounts;
				tempIndexC += curPro * curPro;
			}

			if (tempIndexC - indexC > 0.01 || tempIndexC - indexC < -0.01) {
				// tempIndexC ist derzeit noch nicht gueltig
				flag = 0;
				break;
			}

		}
		periode++;
	}

// zur Festlegung des Offsets in jedem Caesar-Chiffrat
	periode--;
	if (flag == 1 && periode < TextLength) {
		fprintf(stdout, "Richtige Periode=%d\n", periode);
		for (i = 0; i < periode; i++) {
			CountChars(i, periode, h);
			sumCounts = 0;
			for (j = 0; j < NUMCHARS; j++)
				sumCounts += h[j];

			// Wir feststellen zuerst die Position der max Char-Counts, und naechstes fuenfte und sechste Char-Counts
			// Weil die Frequenz der fünfte und sechste Chars nach dem hauefigste Char sehr niedrig sind.
			max = 0;
			for (j = 0; j < NUMCHARS; j++) {
				flag = 1;
				curPro = h[j] / (double) sumCounts;
				nxt5Pro = h[(j + 5) % NUMCHARS] / (double) sumCounts;
				nxt6Pro = h[(j + 6) % NUMCHARS] / (double) sumCounts;
				if (max < curPro && (nxt5Pro) < 0.02 && (nxt6Pro) < 0.02) {
					max = curPro;
					offset = j;
				}
			}
			if (flag == 1) {
				schluessel[i] = 'A' + (offset + NUMCHARS - 4) % NUMCHARS;
			}
		}

		printf("Richtiger Schlüssel: %s\n", schluessel);
		r = 0;
		for (i = 0; i < TextLength; i++) {
			klartexts[i] = (NUMCHARS + TextArray[i] - schluessel[r]) % NUMCHARS
					+ 'A';
			r = (r + 1) % periode;
		}

	} else
		printf("kein Schlüssel gesucht!\n");

// klartexts output
	output(klartexts);

	return 0;
}