Ejemplo n.º 1
0
  private void loadHint(TTGlyph a_glyph, EContourPoint a_point, int a_index) {
    double x = a_point.getX();
    double y = a_point.getY();

    XHint[] hints = a_point.getHint();

    for (int i = 0; i < hints.length; i++) {
      EHint hint = (EHint) hints[i];
      double xHint = hint.getX();
      double yHint = hint.getY();

      if (x == xHint && y == yHint) {
        continue;
      } // if

      double xDelta = xHint - x;
      double yDelta = yHint - y;
      int instruction = TTGlyph.DELTAP1;
      double deltaStep = ((double) Engine.getEm()) / hint.getPpem() / 8;
      int xShift = (int) Math.round(xDelta / deltaStep);
      int yShift = (int) Math.round(yDelta / deltaStep);

      if (xShift == 0 && yShift == 0) {
        continue;
      } // if

      a_glyph.addInstruction(TTGlyph.PUSHB000);
      a_glyph.addInstruction((int) hint.getPpem());
      a_glyph.addInstruction(TTGlyph.SDB);

      if (xShift != 0) {
        a_glyph.addInstruction(TTGlyph.SVTCA1);
        a_glyph.addInstruction(TTGlyph.PUSHB010);
        a_glyph.addInstruction(TTGlyph.toDeltaArg(0, xShift));
        a_glyph.addInstruction(a_index);
        a_glyph.addInstruction(1);
        a_glyph.addInstruction(TTGlyph.DELTAP1);
      } // if

      if (yShift != 0) {
        a_glyph.addInstruction(TTGlyph.SVTCA0);
        a_glyph.addInstruction(TTGlyph.PUSHB010);
        a_glyph.addInstruction(TTGlyph.toDeltaArg(0, yShift));
        a_glyph.addInstruction(a_index);
        a_glyph.addInstruction(1);
        a_glyph.addInstruction(TTGlyph.DELTAP1);
      } // if
    } // for i
  }
  public ArrayList<String> parseXML() throws Exception {
    ArrayList<String> ret = new ArrayList<String>();

    handshake();

    URL url =
        new URL(
            "http://mangaonweb.com/page.do?cdn="
                + cdn
                + "&cpn=book.xml&crcod="
                + crcod
                + "&rid="
                + (int) (Math.random() * 10000));
    String page = DownloaderUtils.getPage(url.toString(), "UTF-8", cookies);

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    InputSource is = new InputSource(new StringReader(page));
    Document d = builder.parse(is);
    Element doc = d.getDocumentElement();

    NodeList pages = doc.getElementsByTagName("page");
    total = pages.getLength();
    for (int i = 0; i < pages.getLength(); i++) {
      Element e = (Element) pages.item(i);
      ret.add(e.getAttribute("path"));
    }

    return (ret);
  }
  public boolean download(DownloadListener dl) throws Exception {
    // 1) get crcod, cdn, and cookies
    handshake();

    // 2) get XML
    ArrayList<String> paths = parseXML();
    dl.setTotal(getTotal());

    // 3) get pages
    byte[] key = {
      99, 49, 51, 53, 100, 54, 56, 56, 57, 57, 99, 56, 50, 54, 99, 101, 100, 55, 99, 52, 57, 98, 99,
      55, 54, 97, 97, 57, 52, 56, 57, 48
    };
    BlowFishKey bfkey = new BlowFishKey(key);
    for (int i = 0; i < paths.size(); i++) {
      if (dl.isDownloadAborted()) return (true);

      // rid is just a random number from 0-9999
      URL url =
          new URL(
              "http://mangaonweb.com/page.do?cdn="
                  + cdn
                  + "&cpn="
                  + paths.get(i)
                  + "&crcod="
                  + crcod
                  + "&rid="
                  + (int) (Math.random() * 10000));

      byte[] encrypted = downloadByteArray(url);
      bfkey.decrypt(encrypted, 0);

      RandomAccessFile output = new RandomAccessFile(dl.downloadPath(this, i), "rw");
      output.write(encrypted);
      output.close();

      dl.downloadIncrement(this);
    }

    dl.downloadFinished(this);

    return (true);
  }
Ejemplo n.º 4
0
  public Track chooseTrack(Random random) {
    Track[] tracks = getTracks();
    float[] probs = new float[tracks.length];

    float totalProb = 0;
    for (int i = 0; i < tracks.length; i++) {
      totalProb += getProbability(tracks[i]);
      probs[i] = totalProb;
      //      System.out.println(Float.toString(totalProb) + " " + getProbability(tracks[i]) + " " +
      // tracks[i]);
    }

    if (totalProb == 0) return null;

    while (true) {
      float rand = Math.abs(random.nextFloat()) * totalProb;
      //      System.out.println("r=" + Float.toString(rand));
      for (int i = 0; i < tracks.length; i++) if (rand <= probs[i]) return tracks[i];
    }
  }