use of com.intellij.openapi.editor.richcopy.model.ColorRegistry in project intellij-community by JetBrains.
the class RtfTransferableData method build.
@Override
protected void build(@NotNull final StringBuilder holder, final int maxLength) {
holder.append(HEADER_PREFIX);
holder.append("{\\colortbl;");
ColorRegistry colorRegistry = mySyntaxInfo.getColorRegistry();
for (int id : colorRegistry.getAllIds()) {
Color color = colorRegistry.dataById(id);
int[] components = getAdjustedColorComponents(color);
holder.append(String.format("\\red%d\\green%d\\blue%d;", components[0], components[1], components[2]));
}
holder.append("}\n");
holder.append("{\\fonttbl");
FontNameRegistry fontNameRegistry = mySyntaxInfo.getFontNameRegistry();
for (int id : fontNameRegistry.getAllIds()) {
String fontName = fontNameRegistry.dataById(id);
holder.append(String.format("{\\f%d %s;}", id, fontName));
}
holder.append("}\n");
holder.append("\n\\s0\\box").append("\\cbpat").append(mySyntaxInfo.getDefaultBackground()).append("\\cb").append(mySyntaxInfo.getDefaultBackground()).append("\\cf").append(mySyntaxInfo.getDefaultForeground());
addFontSize(holder, mySyntaxInfo.getFontSize());
holder.append('\n');
mySyntaxInfo.processOutputInfo(new MyVisitor(holder, myRawText, mySyntaxInfo, maxLength));
holder.append("\\par");
holder.append(HEADER_SUFFIX);
}
use of com.intellij.openapi.editor.richcopy.model.ColorRegistry in project intellij-community by JetBrains.
the class SyntaxInfoConstructionTest method getSyntaxInfo.
private static String getSyntaxInfo(Editor editor, PsiFile psiFile) {
final StringBuilder builder = new StringBuilder();
SelectionModel selectionModel = editor.getSelectionModel();
String selectedText = selectionModel.getSelectedText(true);
assertNotNull(selectedText);
final String text = StringUtil.convertLineSeparators(selectedText);
TextWithMarkupProcessor processor = new TextWithMarkupProcessor() {
@Override
void createResult(SyntaxInfo syntaxInfo, Editor editor) {
final ColorRegistry colorRegistry = syntaxInfo.getColorRegistry();
assertEquals(JBColor.BLACK, colorRegistry.dataById(syntaxInfo.getDefaultForeground()));
assertEquals(JBColor.WHITE, colorRegistry.dataById(syntaxInfo.getDefaultBackground()));
assertEquals((float) editor.getColorsScheme().getEditorFontSize(), syntaxInfo.getFontSize(), 0.01f);
syntaxInfo.processOutputInfo(new MarkupHandler() {
@Override
public void handleText(int startOffset, int endOffset) throws Exception {
builder.append("text=").append(text.substring(startOffset, endOffset)).append('\n');
}
@Override
public void handleForeground(int foregroundId) throws Exception {
builder.append("foreground=").append(colorRegistry.dataById(foregroundId)).append(',');
}
@Override
public void handleBackground(int backgroundId) throws Exception {
builder.append("background=").append(colorRegistry.dataById(backgroundId)).append(',');
}
@Override
public void handleFont(int fontNameId) throws Exception {
assertEquals(1, fontNameId);
}
@Override
public void handleStyle(int style) throws Exception {
builder.append("fontStyle=").append(style).append(',');
}
@Override
public boolean canHandleMore() {
return true;
}
});
}
};
processor.collectTransferableData(psiFile, editor, selectionModel.getBlockSelectionStarts(), selectionModel.getBlockSelectionEnds());
return builder.toString();
}
Aggregations