All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.moaxcp.x11client.protocol.render.AddGlyphs Maven / Gradle / Ivy

There is a newer version: 0.18.2
Show newest version
package com.github.moaxcp.x11client.protocol.render;

import com.github.moaxcp.x11client.protocol.OneWayRequest;
import com.github.moaxcp.x11client.protocol.X11Input;
import com.github.moaxcp.x11client.protocol.X11Output;
import com.github.moaxcp.x11client.protocol.XObject;
import java.io.IOException;
import java.lang.Byte;
import java.lang.Integer;
import java.lang.Override;
import java.util.ArrayList;
import java.util.List;
import lombok.Builder;
import lombok.NonNull;
import lombok.Value;

@Value
@Builder
public class AddGlyphs implements OneWayRequest {
  public static final byte OPCODE = 20;

  private int glyphset;

  @NonNull
  private List glyphids;

  @NonNull
  private List glyphs;

  @NonNull
  private List data;

  public byte getOpCode() {
    return OPCODE;
  }

  public static AddGlyphs readAddGlyphs(X11Input in) throws IOException {
    int javaStart = 1;
    in.readPad(1);
    javaStart += 1;
    short length = in.readCard16();
    javaStart += 2;
    int glyphset = in.readCard32();
    javaStart += 4;
    int glyphsLen = in.readCard32();
    javaStart += 4;
    List glyphids = in.readCard32((int) (Integer.toUnsignedLong(glyphsLen)));
    javaStart += 4 * glyphids.size();
    List glyphs = new ArrayList<>((int) (Integer.toUnsignedLong(glyphsLen)));
    for(int i = 0; i < Integer.toUnsignedLong(glyphsLen); i++) {
      glyphs.add(Glyphinfo.readGlyphinfo(in));
    }
    javaStart += XObject.sizeOf(glyphs);
    List data = in.readByte(javaStart - length);
    AddGlyphs.AddGlyphsBuilder javaBuilder = AddGlyphs.builder();
    javaBuilder.glyphset(glyphset);
    javaBuilder.glyphids(glyphids);
    javaBuilder.glyphs(glyphs);
    javaBuilder.data(data);
    in.readPadAlign(javaBuilder.getSize());
    return javaBuilder.build();
  }

  @Override
  public void write(byte offset, X11Output out) throws IOException {
    out.writeCard8((byte)(Byte.toUnsignedInt(OPCODE) + Byte.toUnsignedInt(offset)));
    out.writePad(1);
    out.writeCard16((short) getLength());
    out.writeCard32(glyphset);
    int glyphsLen = glyphids.size();
    out.writeCard32(glyphsLen);
    out.writeCard32(glyphids);
    for(Glyphinfo t : glyphs) {
      t.write(out);
    }
    out.writeByte(data);
    out.writePadAlign(getSize());
  }

  @Override
  public int getSize() {
    return 12 + 4 * glyphids.size() + XObject.sizeOf(glyphs) + 1 * data.size();
  }

  public static class AddGlyphsBuilder {
    public int getSize() {
      return 12 + 4 * glyphids.size() + XObject.sizeOf(glyphs) + 1 * data.size();
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy