⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 orders.java

📁 cygwin 是一个在windows平台上运行的unix模拟环境
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            text2.setBoxTop(data.getLittleEndian16());
        }

        if ((present & 0x001000) != 0) {
            text2.setBoxRight(data.getLittleEndian16());
        }

        if ((present & 0x002000) != 0) {
            text2.setBoxBottom(data.getLittleEndian16());
        }

        /*
         * Unknown members, seen when connecting to a session that was
         * disconnected with mstsc and with wintach's spreadsheet test.
         */
        if ((present & 0x004000) != 0)
            data.incrementPosition(1);

        if ((present & 0x008000) != 0)
            data.incrementPosition(1);

        if ((present & 0x010000) != 0) {
            data.incrementPosition(1); /* guessing the length here */
            logger
                    .warn("Unknown order state member (0x010000) in text2 order.\n");
        }

        if ((present & 0x020000) != 0)
            data.incrementPosition(4);

        if ((present & 0x040000) != 0)
            data.incrementPosition(4);

        if ((present & 0x080000) != 0) {
            text2.setX(data.getLittleEndian16());
        }

        if ((present & 0x100000) != 0) {
            text2.setY(data.getLittleEndian16());
        }

        if ((present & 0x200000) != 0) {
            text2.setLength(data.get8());

            byte[] text = new byte[text2.getLength()];
            data.copyToByteArray(text, 0, data.getPosition(), text.length);
            data.incrementPosition(text.length);
            text2.setText(text);

            /*
             * if(logger.isInfoEnabled()) logger.info("X: " + text2.getX() + "
             * Y: " + text2.getY() + " Left Clip: " + text2.getClipLeft() + "
             * Top Clip: " + text2.getClipTop() + " Right Clip: " +
             * text2.getClipRight() + " Bottom Clip: " + text2.getClipBottom() + "
             * Left Box: " + text2.getBoxLeft() + " Top Box: " +
             * text2.getBoxTop() + " Right Box: " + text2.getBoxRight() + "
             * Bottom Box: " + text2.getBoxBottom() + " Foreground Color: " +
             * text2.getForegroundColor() + " Background Color: " +
             * text2.getBackgroundColor() + " Font: " + text2.getFont() + "
             * Flags: " + text2.getFlags() + " Mixmode: " + text2.getMixmode() + "
             * Unknown: " + text2.getUnknown() + " Length: " +
             * text2.getLength());
             */
        }

        this.drawText(text2, text2.getClipRight() - text2.getClipLeft(), text2
                .getClipBottom()
                - text2.getClipTop(), text2.getBoxRight() - text2.getBoxLeft(),
                text2.getBoxBottom() - text2.getBoxTop());

    }

    /**
     * Parse a description for a bounding box
     * @param data Packet containing order defining bounding box
     * @param bounds BoundsOrder object in which to store description of bounds
     * @throws OrderException
     */
    private void parseBounds(RdpPacket_Localised data, BoundsOrder bounds)
            throws OrderException {
        int present = 0;

        present = data.get8();

        if ((present & 1) != 0) {
            bounds.setLeft(setCoordinate(data, bounds.getLeft(), false));
        } else if ((present & 16) != 0) {
            bounds.setLeft(setCoordinate(data, bounds.getLeft(), true));
        }

        if ((present & 2) != 0) {
            bounds.setTop(setCoordinate(data, bounds.getTop(), false));
        } else if ((present & 32) != 0) {
            bounds.setTop(setCoordinate(data, bounds.getTop(), true));
        }

        if ((present & 4) != 0) {
            bounds.setRight(setCoordinate(data, bounds.getRight(), false));
        } else if ((present & 64) != 0) {
            bounds.setRight(setCoordinate(data, bounds.getRight(), true));
        }

        if ((present & 8) != 0) {
            bounds.setBottom(setCoordinate(data, bounds.getBottom(), false));
        } else if ((present & 128) != 0) {
            bounds.setBottom(setCoordinate(data, bounds.getBottom(), true));
        }

        if (data.getPosition() > data.getEnd()) {
            throw new OrderException("Too far!");
        }
    }

    /**
     * Retrieve a coordinate from a packet and return as an absolute integer coordinate
     * @param data Packet containing coordinate at current read position
     * @param coordinate Offset coordinate
     * @param delta True if coordinate being read should be taken as relative to offset coordinate, false if absolute
     * @return Integer value of coordinate stored in packet, in absolute form
     */
    private static int setCoordinate(RdpPacket_Localised data, int coordinate,
            boolean delta) {
        byte change = 0;

        if (delta) {
            change = (byte) data.get8();
            coordinate += (int) change;
            return coordinate;
        } else {
            coordinate = data.getLittleEndian16();
            return coordinate;
        }
    }

    /**
     * Read a colour value from a packet
     * @param data Packet containing colour value at current read position
     * @return Integer colour value read from packet
     */
    private static int setColor(RdpPacket_Localised data) {
        int color = 0;
        int i = 0;

        i = data.get8(); // in_uint8(s, i);
        color = i; // *colour = i;
        i = data.get8(); // in_uint8(s, i);
        color |= i << 8; // *colour |= i << 8;
        i = data.get8(); // in_uint8(s, i);
        color |= i << 16; // *colour |= i << 16;

        // color = data.get8();
        // data.incrementPosition(2);
        return color;
    }

    /**
     * Set current cache
     * @param cache Cache object to set as current global cache
     */
    public void registerCache(Cache cache) {
        Orders.cache = cache;
    }

    /**
     * Parse a pen definition
     * @param data Packet containing pen description at current read position
     * @param pen Pen object in which to store pen description
     * @param present Flags defining information available within packet
     * @return True if successful
     */
    private static boolean parsePen(RdpPacket_Localised data, Pen pen,
            int present) {
        if ((present & 0x01) != 0)
            pen.setStyle(data.get8());
        if ((present & 0x02) != 0)
            pen.setWidth(data.get8());
        if ((present & 0x04) != 0)
            pen.setColor(setColor(data));

        return true; // return s_check(s);
    }

    /**
     * Interpret an integer as a 16-bit two's complement number, based on its binary representation
     * @param val Integer interpretation of binary number
     * @return 16-bit two's complement value of input
     */
    private int twosComplement16(int val) {
        return ((val & 0x8000) != 0) ? -((~val & 0xFFFF)+1) : val;
    }

    /**
     * Draw a text2 order to the drawing surface
     * @param text2 Text2Order describing text to be drawn
     * @param clipcx Width of clipping area
     * @param clipcy Height of clipping area
     * @param boxcx Width of bounding box (to draw if > 1)
     * @param boxcy Height of bounding box (to draw if boxcx > 1)
     * @throws RdesktopException
     */
private void drawText(Text2Order text2, int clipcx, int clipcy, int boxcx, int boxcy) throws RdesktopException {
	byte[] text = text2.getText();
	DataBlob entry = null;
	Glyph glyph = null;
	int offset = 0;
	int ptext = 0;
	int length = text2.getLength();
	int x = text2.getX();
	int y = text2.getY();

	if(boxcx > 1) {
	    surface.fillRectangle(text2.getBoxLeft(), text2.getBoxTop(), boxcx, boxcy, text2.getBackgroundColor());
	} else if (text2.getMixmode() == MIX_OPAQUE) {
	    surface.fillRectangle(text2.getClipLeft(), text2.getClipTop(), clipcx, clipcy, text2.getBackgroundColor());
	}
	
	/*
     * logger.debug("X: " + text2.getX() + " Y: " + text2.getY() + " Left Clip: " +
     * text2.getClipLeft() + " Top Clip: " + text2.getClipTop() + " Right Clip: " +
     * text2.getClipRight() + " Bottom Clip: " + text2.getClipBottom() + " Left
     * Box: " + text2.getBoxLeft() + " Top Box: " + text2.getBoxTop() + " Right
     * Box: " + text2.getBoxRight() + " Bottom Box: " + text2.getBoxBottom() + "
     * Foreground Color: " + text2.getForegroundColor() + " Background Color: " +
     * text2.getBackgroundColor() + " Font: " + text2.getFont() + " Flags: " +
     * text2.getFlags() + " Mixmode: " + text2.getMixmode() + " Unknown: " +
     * text2.getUnknown() + " Length: " + text2.getLength());
     */
	for(int i = 0; i < length;) {
	    switch(text[ptext + i]&0x000000ff) {
	    case (0xff):
			if(i + 2 < length) {
			    byte[] data = new byte[text[ptext + i + 2]&0x000000ff];
			    System.arraycopy(text ,ptext , data, 0, text[ptext + i + 2]&0x000000ff);
			    DataBlob db = new DataBlob(text[ptext + i + 2]&0x000000ff, data);
			    cache.putText(text[ptext + i + 1]&0x000000ff, db);
			} else {
			    throw new RdesktopException();
			}
			length -= i + 3;
			ptext = i + 3;
			i = 0;
			break;
		
	    case (0xfe):
			entry = cache.getText(text[ptext + i + 1]&0x000000ff);
			if(entry != null){
			    if((entry.getData()[1] == 0) && ((text2.getFlags() & TEXT2_IMPLICIT_X) == 0)) {
			        if((text2.getFlags() & 0x04) != 0) {
			            y += text[ptext + i + 2]&0x000000ff;
			        } else {
			            x += text[ptext + i + 2]&0x000000ff;
			        }
			    }
            }
			if(i + 2 < length) {
			    i += 3;
			} else {
			    i += 2;
			}
			length -= i;
			ptext = i;
			i = 0;
            // break;
            
			byte[] data = entry.getData();
			for(int j = 0; j < entry.getSize(); j++) {
			    glyph = cache.getFont(text2.getFont(), data[j]&0x000000ff);
			    if((text2.getFlags() & TEXT2_IMPLICIT_X) == 0) {
				offset = data[++j]&0x000000ff;
				if((offset & 0x80) !=0) {
                    if((text2.getFlags() & TEXT2_VERTICAL) != 0) {
                        int var = this.twosComplement16((data[j+1]&0xff) | ((data[j+2]&0xff) << 8));
                        y += var;
                        j += 2;
				    } else {
                        int var = this.twosComplement16((data[j+1]&0xff) | ((data[j+2]&0xff) << 8));
                        x += var;
                        j += 2;
				    }
				} else {
				    if((text2.getFlags() & TEXT2_VERTICAL) != 0) {
					y += offset;
				    } else {
					x += offset;
				    }
				}
			    }
			    if(glyph != null) {
                    //if((text2.getFlags() & TEXT2_VERTICAL) != 0) logger.info("Drawing glyph: (" + (x + (short)glyph.getOffset()) + ", " + (y + (short)glyph.getBaseLine()) + ")"  );
                    surface.drawGlyph(text2.getMixmode(), x + (short)glyph.getOffset(),
                                  y + (short)glyph.getBaseLine(), glyph.getWidth(),
                                  glyph.getHeight(), glyph.getFontData(),
                                  text2.getBackgroundColor(), text2.getForegroundColor());   
                
				if((text2.getFlags() & TEXT2_IMPLICIT_X) != 0) {
                   x += glyph.getWidth();
				}
			    }    
			}
			break;

	    default:
			glyph = cache.getFont(text2.getFont(), text[ptext + i]&0x000000ff);
			if((text2.getFlags() & TEXT2_IMPLICIT_X) == 0) {
			    offset = text[ptext + (++i)]&0x000000ff;
			    if((offset & 0x80) !=0) {
				if((text2.getFlags() & TEXT2_VERTICAL) != 0) {
				    //logger.info("y +=" + (text[ptext + (i+1)]&0x000000ff) + " | " + ((text[ptext + (i+2)]&0x000000ff) << 8));
                    int var = this.twosComplement16((text[ptext + i+1]&0x000000ff) | ((text[ptext + i+2]&0x000000ff) << 8));
                    y += var;
                    i += 2;
				} else {
                    int var = this.twosComplement16((text[ptext + i+1]&0x000000ff) | ((text[ptext + i+2]&0x000000ff) << 8));
                    x += var;
                    i += 2;
				}
			    } else {
				if((text2.getFlags() & TEXT2_VERTICAL) != 0) {
				    y += offset; 
				} else {
				    x += offset;
				}
			    }
			}
			if(glyph != null) {
			    surface.drawGlyph(text2.getMixmode(), x + (short)glyph.getOffset(),
					      y + (short)glyph.getBaseLine(), glyph.getWidth(),
					      glyph.getHeight(), glyph.getFontData(), 
					      text2.getBackgroundColor(), text2.getForegroundColor());
			    
			    if((text2.getFlags() & TEXT2_IMPLICIT_X) != 0) x += glyph.getWidth();
			}
			i++;
		break;
	    }
	}
    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -