Пример #1
0
/*!
  Replaces the entire contents of the document
  with the given HTML-formatted text in the \a text string
*/
void RichString::setHtml(const QString &text)
{
    QTextDocument doc;
    doc.setHtml(text);
    QTextBlock block = doc.firstBlock();
    QTextBlock::iterator it;
    for (it = block.begin(); !(it.atEnd()); ++it) {
        QTextFragment textFragment = it.fragment();
        if (textFragment.isValid()) {
            Format fmt;
            fmt.setFont(textFragment.charFormat().font());
            fmt.setFontColor(textFragment.charFormat().foreground().color());
            addFragment(textFragment.text(), fmt);
        }
    }
}
Пример #2
0
Shader::Shader(const char* vert_src, const char* frag_src)
{
  g_shProg = glCreateProgram();
  addVertex(vert_src);
  addFragment(frag_src);
}
Пример #3
0
/*!
    Constructs a plain string with the given \a text.
*/
RichString::RichString(const QString text)
    :d(new RichStringPrivate)
{
    addFragment(text, Format());
}
Пример #4
0
void EhFrame::addFDE(EhFrame::FDE& pFDE, bool pAlsoAddFragment) {
  pFDE.getCIE().add(pFDE);
  if (pAlsoAddFragment)
    addFragment(pFDE);
}
Пример #5
0
void EhFrame::addCIE(EhFrame::CIE& pCIE, bool pAlsoAddFragment) {
  m_CIEs.push_back(&pCIE);
  if (pAlsoAddFragment)
    addFragment(pCIE);
}
Пример #6
0
	int NyARLabeling_Rle::imple_labeling(const INyARRaster& i_raster,int i_th,int i_top, int i_bottom,NyARRleLabelFragmentInfoStack& o_stack)
	{
		// リセット処理
		RleInfoStack& rlestack=*this->_rlestack;
		rlestack.clear();

		//
		TRleElement* rle_prev = this->_rle1;
		TRleElement* rle_current = this->_rle2;
		int len_prev = 0;
		int len_current = 0;
		const int width = i_raster.getWidth();
		int* in_buf = (int*) i_raster.getBuffer();

		int id_max = 0;
		int label_count=0;
		// 初段登録

		len_prev = toRel(in_buf, i_top, width, rle_prev);
		for (int i = 0; i < len_prev; i++) {
			// フラグメントID=フラグメント初期値、POS=Y値、RELインデクス=行
			addFragment(rle_prev[i], id_max, i_top, rlestack);
			id_max++;
			// nofの最大値チェック
			label_count++;
		}
		TRleInfo** const f_array = rlestack.getArray().item;
		// 次段結合
		for (int y = i_top + 1; y < i_bottom; y++) {
			// カレント行の読込
			len_current = toRel(in_buf, y * width, width, rle_current);
			int index_prev = 0;

			for (int i = 0; i < len_current; i++) {
				// index_prev,len_prevの位置を調整する
				int id = -1;
				// チェックすべきprevがあれば確認
				while (index_prev < len_prev) {
					if (rle_current[i].l - rle_prev[index_prev].r > 0) {// 0なら8方位ラベリング
						// prevがcurの左方にある→次のフラグメントを探索
						index_prev++;
						continue;
					} else if (rle_prev[index_prev].l - rle_current[i].r > 0) {// 0なら8方位ラベリングになる
						// prevがcur右方にある→独立フラグメント
						addFragment(rle_current[i], id_max, y,rlestack);
						id_max++;
						label_count++;
						// 次のindexをしらべる
						goto SCAN_CUR;
					}
					id=rle_prev[index_prev].fid;//ルートフラグメントid
					TRleInfo& id_ptr = *f_array[id];
					//結合対象(初回)->prevのIDをコピーして、ルートフラグメントの情報を更新
					rle_current[i].fid = id;//フラグメントIDを保存
					//
					const int l= rle_current[i].l;
					const int r= rle_current[i].r;
					const int len=r-l;
					//結合先フラグメントの情報を更新する。
					id_ptr.area += len;
					//tとentry_xは、結合先のを使うので更新しない。
					id_ptr.clip_l=l<id_ptr.clip_l?l:id_ptr.clip_l;
					id_ptr.clip_r=r>id_ptr.clip_r?r-1:id_ptr.clip_r;
					id_ptr.clip_b=y;
					id_ptr.pos_x+=(len*(2*l+(len-1)))/2;
					id_ptr.pos_y+=y*len;
					//多重結合の確認(2個目以降)
					index_prev++;
					while (index_prev < len_prev) {
						if (rle_current[i].l - rle_prev[index_prev].r > 0) {// 0なら8方位ラベリング
							// prevがcurの左方にある→prevはcurに連結していない。
							goto SCAN_PREV;
						} else if (rle_prev[index_prev].l - rle_current[i].r > 0) {// 0なら8方位ラベリングになる
							// prevがcurの右方にある→prevはcurに連結していない。
							index_prev--;
							goto SCAN_CUR;
						}
						// prevとcurは連結している→ルートフラグメントの統合

						//結合するルートフラグメントを取得
						const int prev_id =rle_prev[index_prev].fid;
						TRleInfo& prev_ptr = *f_array[prev_id];
						if (id != prev_id){
							label_count--;
							//prevとcurrentのフラグメントidを書き換える。
							for(int i2=index_prev;i2<len_prev;i2++){
								//prevは現在のidから最後まで
								if(rle_prev[i2].fid==prev_id){
									rle_prev[i2].fid=id;
								}
							}
							for(int i2=0;i2<i;i2++){
								//currentは0から現在-1まで
								if(rle_current[i2].fid==prev_id){
									rle_current[i2].fid=id;
								}
							}

							//現在のルートフラグメントに情報を集約
							id_ptr.area +=prev_ptr.area;
							id_ptr.pos_x+=prev_ptr.pos_x;
							id_ptr.pos_y+=prev_ptr.pos_y;
							//tとentry_xの決定
							if (id_ptr.clip_t > prev_ptr.clip_t) {
								// 現在の方が下にある。
								id_ptr.clip_t = prev_ptr.clip_t;
								id_ptr.entry_x = prev_ptr.entry_x;
							}else if (id_ptr.clip_t < prev_ptr.clip_t) {
								// 現在の方が上にある。prevにフィードバック
							} else {
								// 水平方向で小さい方がエントリポイント。
								if (id_ptr.entry_x > prev_ptr.entry_x) {
									id_ptr.entry_x = prev_ptr.entry_x;
								}else{
								}
							}
							//lの決定
							if (id_ptr.clip_l > prev_ptr.clip_l) {
								id_ptr.clip_l=prev_ptr.clip_l;
							}else{
							}
							//rの決定
							if (id_ptr.clip_r < prev_ptr.clip_r) {
								id_ptr.clip_r=prev_ptr.clip_r;
							}else{
							}
							//bの決定

							//結合済のルートフラグメントを無効化する。
							prev_ptr.area=0;
						}


						index_prev++;
					}
					index_prev--;
					break;
					SCAN_PREV:;
				}
				// curにidが割り当てられたかを確認
				// 右端独立フラグメントを追加
				if (id < 0){
					addFragment(rle_current[i], id_max, y,rlestack);
					id_max++;
					label_count++;
				}
			SCAN_CUR:;
			}
			// prevとrelの交換
			TRleElement* tmp = rle_prev;
			rle_prev = rle_current;
			len_prev = len_current;
			rle_current = tmp;
		}
		//対象のラベルだけ転写
		o_stack.init(label_count);
		NyARRleLabelFragmentInfo** o_dest_array=o_stack.getArray().item;
		const int max=this->_max_area;
		const int min=this->_min_area;
		int active_labels=0;
		for(int i=id_max-1;i>=0;i--){
			const int area=f_array[i]->area;
			if(area<min || area>max){//対象外のエリア0のもminではじく
				continue;
			}
			//
			const TRleInfo src_info=*f_array[i];
			NyARRleLabelFragmentInfo& dest_info=*o_dest_array[active_labels];
			dest_info.area=area;
			dest_info.clip_b=src_info.clip_b;
			dest_info.clip_r=src_info.clip_r;
			dest_info.clip_t=src_info.clip_t;
			dest_info.clip_l=src_info.clip_l;
			dest_info.entry_x=src_info.entry_x;
			dest_info.pos_x=(double)(src_info.pos_x/src_info.area);
			dest_info.pos_y=(double)(src_info.pos_y/src_info.area);
			active_labels++;
		}
		//ラベル数を再設定
		o_stack.pops(label_count-active_labels);
		//ラベル数を返却
		return active_labels;
	}	
// Parse one line of text, create fragments, end line when overflow width.
void PaintText::parseFragmentsWithCharBreak(
    TextLine& line,             // Line descriptor.
    int startPos,               // Location of beginning of string to examine.
    int endPos,                 // Location of one past the last character to examine.
    float maxWidth,             // Can't go beyond this width.
    bool ellipsis,              // True = if line doesn't fit, append ellipsis.
    int* resultPos              // OUT: Ptr to string past the format string.
) {
    int curPos = startPos;          // Beginning of current part of the string we are working on.
    double curWidth = maxWidth;     // The width left to work with.

    bool forceEndLine = false;      // True = end-of-line through format.  False = char width.

    while(curPos < endPos) {
        // Is there a format char left in this string?
        const string::size_type formatPos = m_text.find(DT_FORMAT_CHAR, curPos);
        if(formatPos == std::string::npos || formatPos >= endPos) {
            // No format char.
            addFragment(line, endPos, curPos, curWidth);
            break;
        }

        // Create fragment for characters before the format char.
        addFragment(line, formatPos, curPos, curWidth);
        if(curPos < formatPos) {
            // Format is past the max width.  We're done with this line.
            break;
        }

        // Interpret the format command.
        assert(m_text[curPos] == DT_FORMAT_CHAR);
        curPos++;       // Look at the command char.
        if(curPos >= endPos) {
            // No command char.  String ends with single "#".  Ignore it.
            curPos = endPos - 1;
            break;
        }
        if(m_text[curPos] == DT_FORMAT_CHAR) {
            // Double format char.  Equals one format char.
            const int oldPos = curPos;
            addFragment(line, curPos+1, curPos, curWidth);
            if(curPos == oldPos) {
                // No room in the line for the one char.  Leave it for next line.
                curPos--;           // Put chars back in string.
                break;              // End of this line.
            }
        } else {
            parseFormat(curPos, &curPos, &forceEndLine);
            if(forceEndLine) {
                break;
            }
        }
    }

    if(!forceEndLine && curPos < endPos) {
        if(ellipsis) {
            // We need to append an ellipsis. We didn't use the whole string, and we didn't end
            //  the line because of a format command.
            // We use the font at the end of the line.  This is a hack, but it seems like a
            //  reasonable compromise.  If we use the font from the beginning of the line, suppose the
            //  line starts out with bold, followed by a non-bold explanation?
            // We use the color of the last fragment before the ellipsis.

            const Font& font = m_layout.fontStack.back();
            const double ellipsisWidth = font.stringWidth(ELLIPSIS_STRING);
            // If ellipsis doesn't fit in the original width, just ship the truncated string.
            if(ellipsisWidth < maxWidth) {
                while(line.fragments.size() > 0) { 
                    TextFragment& frag = line.fragments.back();
                    // Remove enough space in the last fragment to be able to append the ellipsis.
                    int i;
                    for(i=frag.end; i>=frag.start; i--) {
                        curWidth -= frag.font.charWidth(m_text[i]);
                        if(curWidth+ellipsisWidth <= maxWidth) {
                            // If we back up this far, the ellipsis will fit in the max width.
                            frag.end = i;
                            break;
                        }
                    }
                    if(i < frag.start) {
                        // Used up the whole fragment and still didn't find enough space.
                        line.fragments.pop_back();
                    } else {
                        // Create an ellipsis fragment and append it to the line.
                        TextFragment newFrag = frag;
                        newFrag.start = ELLIPSIS_FRAGMENT;
                        line.fragments.push_back(newFrag);
                        curWidth += ellipsisWidth;
                        break;
                    }
                }
            }
        } else {
            // Get rid of word break chars at the end of this line.
            // First, make sure to skip over any white space.
            while(curPos < endPos && isWordBreak(m_text[curPos])) {
                curPos++;
            }

            // Now, get rid of any word break chars at the tail end of our fragment list.
            while(line.fragments.size() > 0) { 
                TextFragment& frag = line.fragments.back();
                int i;
                for(i=frag.end; i>=frag.start; i--) {
                    if(!isWordBreak(m_text[i])) {
                        break;
                    }
                    curWidth -= frag.font.charWidth(m_text[i]);
                }
                if(i >= frag.start) {
                    // Found something besides a word break in this fragment.
                    break;
                }
                // Used up the whole fragment.  Start on the next one.
                line.fragments.pop_back();
            }
        }
    }

    // Set the width of this line.
    line.width = maxWidth - curWidth;

    // And make sure we know how far we got in the string.
    *resultPos = curPos;
}