int AdvancePosToAlignmentEnd(std::vector<char> &ops, int &pos) { int start = pos; while (pos < ops.size() and ops[pos] != 'N' and !IsClipping(ops[pos])) { pos++; } return pos - start; }
int AdvancePastClipping(std::vector<int> &lengths, std::vector<char> &ops, int &opIndex, int &numSoftClipped) { int numClipped = 0; numSoftClipped = 0; while (opIndex < lengths.size() and IsClipping(ops[opIndex])) { numClipped += lengths[opIndex]; if (ops[opIndex] == 'S') { numSoftClipped+= lengths[opIndex]; } ++opIndex; } return numClipped; }
void PDFWriter::DrawString(char *string, float escapementNoSpace, float escapementSpace) { REPORT(kDebug, fPage, "DrawString string=\"%s\", escapementNoSpace=%f, " "escapementSpace=%f, at %f, %f", string, escapementNoSpace, escapementSpace, fState->penX, fState->penY); if (IsDrawing()) { // text color is always the high color and not the pattern! SetColor(fState->foregroundColor); } // convert string to UTF8 BString utf8; if (fState->beFont.Encoding() == B_UNICODE_UTF8) { utf8 = string; } else { ToUtf8(fState->beFont.Encoding()-1, string, utf8); } // convert string in UTF8 to unicode UCS2 BString unicode; ToUnicode(utf8.String(), unicode); // need font object to calculate width of utf8 code point BFont font = fState->beFont; font.SetEncoding(B_UNICODE_UTF8); // constants to calculate position of next character const double rotation = DEGREE2RAD(fState->beFont.Rotation()); const bool rotate = rotation != 0.0; const double cos1 = rotate ? cos(rotation) : 1; const double sin1 = rotate ? -sin(rotation) : 0; BPoint start(fState->penX, fState->penY); BeginTransparency(); // If !MakesPDF() all the effort below just for the bounding box! // draw each character const char *c = utf8.String(); const unsigned char *u = (unsigned char*)unicode.String(); for (int i = 0; i < unicode.Length(); i += 2) { int s = CodePointSize((char*)c); float w = font.StringWidth(c, s); if (MakesPDF() && IsClipping()) { ClipChar(&font, (char*)u, c, s, w); } else { DrawChar(u[0]*256+u[1], c, s); } // position of next character if (*(unsigned char*)c <= 0x20) { // should test if c is a white-space! w += escapementSpace; } else { w += escapementNoSpace; } fState->penX += w * cos1; fState->penY += w * sin1; // next character c += s; u += 2; } EndTransparency(); // text line processing (for non rotated text only!) BPoint end(fState->penX, fState->penY); BRect bounds; font_height height; font.GetHeight(&height); bounds.left = start.x; bounds.right = end.x; bounds.top = start.y - height.ascent; bounds.bottom = end.y + height.descent; TextSegment* segment = new TextSegment(utf8.String(), start, escapementSpace, escapementNoSpace, &bounds, &font, pdfSystem()); fTextLine.Add(segment); }
void CIGAROpsToBlocks(std::vector<int> &lengths, std::vector<char> &ops, int &cigarPos, int &cigarEnd, int &qPos, int &tPos, AlignmentCandidate<> &aln) { int gapIndex = 0; DNALength qStart = qPos, tStart = tPos; assert(cigarPos >= cigarEnd or !IsClipping(ops[cigarPos])); // // Advance past any skipped portion. // int numSkipped = AdvancePastSkipped(lengths, ops, cigarPos); tPos += numSkipped; // // Process the gaps before the first match. // // // If there is nothing left, just bail. blasr::GapList gap; cigarEnd = cigarPos; AdvancePosToAlignmentEnd(ops, cigarEnd); if (cigarPos >= cigarEnd) { return; } // // Process any gap that the aligner produces before the first match // begins. // int qAdvance, tAdvance; ProcessGap(lengths, ops, cigarPos, cigarEnd, gap, qAdvance, tAdvance); aln.gaps.push_back(gap); qPos += qAdvance; tPos += tAdvance; // // Now add gaps. // while(cigarPos < cigarEnd) { // // The next operation must be a match. // int matchLength = ProcessMatch(lengths, ops, cigarPos, cigarEnd); blasr::Block b; b.qPos = qPos - qStart; b.tPos = tPos - tStart; b.length = matchLength; aln.blocks.push_back(b); qPos += b.length; tPos += b.length; ProcessGap(lengths, ops, cigarPos, cigarEnd, gap, qAdvance, tAdvance); aln.gaps.push_back(gap); tPos += tAdvance; qPos += qAdvance; } }