CPDF_TextPage::GenerateCharacter CPDF_TextPage::ProcessInsertObject( const CPDF_TextObject* pObj, const CFX_Matrix& formMatrix) { FindPreviousTextObject(); TextOrientation WritingMode = GetTextObjectWritingMode(pObj); if (WritingMode == TextOrientation::Unknown) WritingMode = GetTextObjectWritingMode(m_pPreTextObj.Get()); size_t nItem = m_pPreTextObj->CountItems(); if (nItem == 0) return GenerateCharacter::None; CPDF_TextObjectItem PrevItem; m_pPreTextObj->GetItemInfo(nItem - 1, &PrevItem); CPDF_TextObjectItem item; pObj->GetItemInfo(0, &item); const CFX_FloatRect& this_rect = pObj->GetRect(); const CFX_FloatRect& prev_rect = m_pPreTextObj->GetRect(); WideString wstrItem = pObj->GetFont()->UnicodeFromCharCode(item.m_CharCode); if (wstrItem.IsEmpty()) wstrItem += static_cast<wchar_t>(item.m_CharCode); wchar_t curChar = wstrItem[0]; if (WritingMode == TextOrientation::Horizontal) { if (EndHorizontalLine(this_rect, prev_rect)) { return IsHyphen(curChar) ? GenerateCharacter::Hyphen : GenerateCharacter::LineBreak; } } else if (WritingMode == TextOrientation::Vertical) { if (EndVerticalLine(this_rect, prev_rect, m_CurlineRect, pObj->GetFontSize(), m_pPreTextObj->GetFontSize())) { return IsHyphen(curChar) ? GenerateCharacter::Hyphen : GenerateCharacter::LineBreak; } } float last_pos = PrevItem.m_Origin.x; uint32_t nLastWidth = GetCharWidth(PrevItem.m_CharCode, m_pPreTextObj->GetFont()); float last_width = nLastWidth * m_pPreTextObj->GetFontSize() / 1000; last_width = fabs(last_width); uint32_t nThisWidth = GetCharWidth(item.m_CharCode, pObj->GetFont()); float this_width = fabs(nThisWidth * pObj->GetFontSize() / 1000); float threshold = std::max(last_width, this_width) / 4; CFX_Matrix prev_matrix = m_pPreTextObj->GetTextMatrix() * m_perMatrix; CFX_Matrix prev_reverse = prev_matrix.GetInverse(); CFX_PointF pos = prev_reverse.Transform(formMatrix.Transform(pObj->GetPos())); if (last_width < this_width) threshold = prev_reverse.TransformDistance(threshold); bool bNewline = false; if (WritingMode == TextOrientation::Horizontal) { CFX_FloatRect rect = m_pPreTextObj->GetRect(); float rect_height = rect.Height(); rect.Normalize(); if ((rect.IsEmpty() && rect_height > 5) || ((pos.y > threshold * 2 || pos.y < threshold * -3) && (fabs(pos.y) >= 1 || fabs(pos.y) > fabs(pos.x)))) { bNewline = true; if (nItem > 1) { CPDF_TextObjectItem tempItem; m_pPreTextObj->GetItemInfo(0, &tempItem); CFX_Matrix m = m_pPreTextObj->GetTextMatrix(); if (PrevItem.m_Origin.x > tempItem.m_Origin.x && m_DisplayMatrix.a > 0.9 && m_DisplayMatrix.b < 0.1 && m_DisplayMatrix.c < 0.1 && m_DisplayMatrix.d < -0.9 && m.b < 0.1 && m.c < 0.1) { CFX_FloatRect re(0, m_pPreTextObj->GetRect().bottom, 1000, m_pPreTextObj->GetRect().top); if (re.Contains(pObj->GetPos())) { bNewline = false; } else { if (CFX_FloatRect(0, pObj->GetRect().bottom, 1000, pObj->GetRect().top) .Contains(m_pPreTextObj->GetPos())) { bNewline = false; } } } } } } if (bNewline) { return IsHyphen(curChar) ? GenerateCharacter::Hyphen : GenerateCharacter::LineBreak; } if (pObj->CountChars() == 1 && IsHyphenCode(curChar) && IsHyphen(curChar)) return GenerateCharacter::Hyphen; if (curChar == L' ') return GenerateCharacter::None; WideString PrevStr = m_pPreTextObj->GetFont()->UnicodeFromCharCode(PrevItem.m_CharCode); wchar_t preChar = PrevStr.Last(); if (preChar == L' ') return GenerateCharacter::None; CFX_Matrix matrix = pObj->GetTextMatrix() * formMatrix; float threshold2 = static_cast<float>(std::max(nLastWidth, nThisWidth)); threshold2 = NormalizeThreshold(threshold2, 400, 700, 800); if (nLastWidth >= nThisWidth) { threshold2 *= fabs(m_pPreTextObj->GetFontSize()); } else { threshold2 *= fabs(pObj->GetFontSize()); threshold2 = matrix.TransformDistance(threshold2); threshold2 = prev_reverse.TransformDistance(threshold2); } threshold2 /= 1000; if ((threshold2 < 1.4881 && threshold2 > 1.4879) || (threshold2 < 1.39001 && threshold2 > 1.38999)) { threshold2 *= 1.5; } return GenerateSpace(pos, last_pos, this_width, last_width, threshold2) ? GenerateCharacter::Space : GenerateCharacter::None; }
ST_ErrorCode_t BLAST_RC6AEncode(const U32 *UserBuf_p, STBLAST_Symbol_t *SymbolBuf_p, U32 *SymbolsEncoded_p, const STBLAST_ProtocolParams_t *ProtocolParams_p) { U32 SymbolCount = 0; int i; U32 Data = 0; BOOL LastUpdatedMark; *SymbolsEncoded_p = 0; /* Reset symbol count */ /************************************************************** * The format of an RC6A command is as follows: * * | H,S,M,T | C[8] | P[20] * * H,M.S,T - Header, Start, Mode, Trailer bits * C - Customer code * P - Payload */ /* generate header+startbit, mode6, trailer */ GenerateSymbol( MID_6T, MID_2T, SymbolBuf_p); SymbolBuf_p++; SymbolCount++; GenerateSymbol( MID_1T, MID_1T, SymbolBuf_p); SymbolBuf_p++; SymbolCount++; GenerateSymbol( MID_1T, MID_1T, SymbolBuf_p); SymbolBuf_p++; SymbolCount++; GenerateSymbol( MID_1T, MID_2T, SymbolBuf_p); SymbolBuf_p++; SymbolCount++; GenerateSymbol( MID_1T, MID_2T, SymbolBuf_p); SymbolBuf_p++; SymbolCount++; /* generate the end of the trailer (2T) plus the first bit of the cust code */ if((ProtocolParams_p->RC6A.CustomerCode & (1 << (7))) != 0) { /* Bit = 1 */ GenerateMark( MID_3T, SymbolBuf_p); LastUpdatedMark = TRUE; } else { /* Bit = 0 */ GenerateMark( MID_2T, SymbolBuf_p); LastUpdatedMark = TRUE; } /* compile the rest of the bits (typically 20) into a U32 Data*/ /* Customercode */ Data = (U32)ProtocolParams_p->RC6A.CustomerCode; Data <<= ProtocolParams_p->RC6A.NumberPayloadBits; /* Payload - before ORing with Data, ensure only NumberPayloadBits of data remain in *UserBuf */ Data |= ((*UserBuf_p << (32-ProtocolParams_p->RC6A.NumberPayloadBits)) >> (32-ProtocolParams_p->RC6A.NumberPayloadBits) ); /* generate end of trailer and customer code */ for(i = 8+ProtocolParams_p->RC6A.NumberPayloadBits-1; i > -1; i--) { if((Data & (1 << (i))) != 0) { /* Bit = 1 */ if(LastUpdatedMark) { ExtendMark(MID_1T, SymbolBuf_p); GenerateSpace(MID_1T, SymbolBuf_p); LastUpdatedMark = FALSE; } else { SymbolBuf_p++; SymbolCount++; GenerateSymbol(MID_1T, MID_1T, SymbolBuf_p); LastUpdatedMark = FALSE; } } else { /* Bit = 0 */ if(LastUpdatedMark) { GenerateSpace(MID_1T, SymbolBuf_p); SymbolBuf_p++; SymbolCount++; GenerateMark(MID_1T, SymbolBuf_p); LastUpdatedMark = TRUE; } else { ExtendSpace(MID_1T, SymbolBuf_p); SymbolBuf_p++; SymbolCount++; GenerateMark(MID_1T, SymbolBuf_p); LastUpdatedMark = TRUE; } } } SymbolCount++; /* Set symbols encoded count */ *SymbolsEncoded_p = SymbolCount; /* Can't really go wrong with this */ return ST_NO_ERROR; }