コード例 #1
0
ファイル: TextRun.cs プロジェクト: hanwangkun/npoi
	/**
	 * Internal constructor and Initializer
	 */
	private TextRun(TextHeaderAtom tha, TextBytesAtom tba, TextCharsAtom tca, StyleTextPropAtom sta) {
		_headerAtom = tha;
		_styleAtom = sta;
		if(tba != null) {
			_byteAtom = tba;
			_isUnicode = false;
		} else {
			_charAtom = tca;
			_isUnicode = true;
		}
		String RunRawText = GetText();

		// Figure out the rich text Runs
		LinkedList pStyles = new LinkedList();
		LinkedList cStyles = new LinkedList();
		if(_styleAtom != null) {
			// Get the style atom to grok itself
			_styleAtom.SetParentTextSize(RunRawText.Length);
			pStyles = _styleAtom.GetParagraphStyles();
			cStyles = _styleAtom.GetCharacterStyles();
		}
        buildRichTextRuns(pStyles, cStyles, RunRawText);
	}
コード例 #2
0
ファイル: TextRun.cs プロジェクト: hanwangkun/npoi
	/**
	* Constructs a Text Run from a Ascii text block
	*
	* @param tha the TextHeaderAtom that defines what's what
	* @param tba the TextBytesAtom Containing the text
	* @param sta the StyleTextPropAtom which defines the character stylings
	*/
	public TextRun(TextHeaderAtom tha, TextBytesAtom tba, StyleTextPropAtom sta) {
		this(tha,tba,null,sta);
	}
コード例 #3
0
ファイル: TextRun.cs プロジェクト: hanwangkun/npoi
	/**
	 * Saves the given string to the records. Doesn't
	 *  touch the stylings.
	 */
	private void storeText(String s) {
		// Remove a single trailing \r, as there is an implicit one at the
		//  end of every record
		if(s\.EndsWith("\r")) {
			s = s.Substring(0, s.Length-1);
		}

		// Store in the appropriate record
		if(_isUnicode) {
			// The atom can safely convert to unicode
			_charAtom.SetText(s);
		} else {
			// Will it fit in a 8 bit atom?
			bool HasMultibyte = StringUtil.HasMultibyte(s);
			if(! hasMultibyte) {
				// Fine to go into 8 bit atom
				byte[] text = new byte[s.Length];
				StringUtil.PutCompressedUnicode(s,text,0);
				_byteAtom.SetText(text);
			} else {
				// Need to swap a TextBytesAtom for a TextCharsAtom

				// Build the new TextCharsAtom
				_charAtom = new TextCharsAtom();
				_charAtom.SetText(s);

				// Use the TextHeaderAtom to do the swap on the parent
				RecordContainer parent = _headerAtom.GetParentRecord();
				Record[] cr = parent.GetChildRecords();
				for(int i=0; i<cr.Length; i++) {
					// Look for TextBytesAtom
					if(cr[i].Equals(_byteAtom)) {
						// Found it, so Replace, then all done
						cr[i] = _charAtom;
						break;
					}
				}

				// Flag the change
				_byteAtom = null;
				_isUnicode = true;
			}
		}
        /**
         * If TextSpecInfoAtom is present, we must update the text size in it,
         * otherwise the ppt will be corrupted
         */
        if(_records != null) for (int i = 0; i < _records.Length; i++) {
            if(_records[i] is TextSpecInfoAtom){
                TextSpecInfoAtom specAtom = (TextSpecInfoAtom)_records[i];
                if((s.Length + 1) != specAtom.GetCharactersCovered()){
                    specAtom.reset(s.Length + 1);
                }
            }
        }
	}