public void writeString(String text, List<TextPosition> line) throws IOException {

    String lineString = rf.convertListToString(line);
    System.out.println(lineString);
    if (normalizeString(lineString)
        .toLowerCase()
        .contains(normalizeString(nextPoetryName).toLowerCase())) {
      contToRead = false;
    }
    String a = normalizeString(lineString);
    String b = normalizeString(currentPoetryName);
    if (normalizeString(lineString)
        .toLowerCase()
        .contains(normalizeString(currentPoetryName).toLowerCase())) {
      contToRead = true;
    }

    if (contToRead == true) {

      float[] borders = getLineStartEnd(line);

      lastInsertedWorkLineId =
          db.insertWorkline(lineString.trim(), borders[0], borders[1], currentWorkId);
      getTheWords(line);
    }
  }
  private void getTheCharacters(List<TextPosition> word) {

    for (int i = 0; i < word.size(); i++) {
      TextPosition cha = word.get(i);

      List<TextPosition> sublist = word.subList(i, i);
      db.insertWordCharacter(
          rf.convertToCorrectForm(cha),
          cha.getXDirAdj(),
          cha.getXDirAdj(),
          lastInsertedWordId,
          rf.isBold(sublist),
          rf.isItalic(sublist),
          getFont(sublist));
    }
  }
  private void getTheWords(List<TextPosition> line) {
    float wordStart = 0;
    float wordEnd = 0;
    boolean isNextStart = false;
    StringBuilder builder = new StringBuilder();
    int startIndex = 0;

    for (int i = 0; i < line.size(); i++) {
      TextPosition pos = line.get(i);
      if (i == 0) {
        wordStart = pos.getXDirAdj();
        builder.delete(0, builder.length());
        startIndex = i;
      }

      if (isNextStart == true) {
        isNextStart = false;
        wordStart = pos.getXDirAdj();
        builder.delete(0, builder.length());
        startIndex = i;
      }

      if (rf.convertToCorrectForm(pos).trim().equals("") || i == (line.size() - 1)) {
        if (i == (line.size() - 1)) {
          builder.append(rf.convertToCorrectForm(pos));
          i++;
        }
        isNextStart = true;
        wordEnd = pos.getXDirAdj();
        List<TextPosition> word = line.subList(startIndex, i);
        lastInsertedWordId =
            db.insertWord(
                builder.toString(),
                wordStart,
                wordEnd,
                lastInsertedWorkLineId,
                rf.isBold(word),
                rf.isItalic(word),
                getFont(word));
        getTheCharacters(word);
      }

      builder.append(rf.convertToCorrectForm(pos));
    }
  }
  private void initialize() {

    nextPoetryName = db.nextWorkName(currentWorkId).trim();
  }