public string load() { if (File.Exists(path)) { BinaryFormatter binary = new BinaryFormatter(); FileStream fStream = File.Open(path, FileMode.Open); SurrogateSelector surrogater = new SurrogateSelector(); Surrogates.AddSurrogates(ref surrogater); binary.SurrogateSelector = surrogater; DataValues saver = (DataValues)binary.Deserialize(fStream); fStream.Close(); dateLogic.Hours = saver.Hours; dateLogic.Minutes = saver.Minutes; dateLogic.Day = saver.Day; dateLogic.Month = saver.Month; dateLogic.Year = saver.Year; keywords.Keywords = saver.Keywords; objects.loadObjects(saver.GameObjects); return("Successfully Loaded your data!\n"); } return("Could not find the data, have you saved before?"); }
public string Save() { //Create a new instance of the BinaryFormatter BinaryFormatter binary = new BinaryFormatter(); //Create a new instance of the SurrogateSelector SurrogateSelector surrogate = new SurrogateSelector(); //Create a new file on the path FileStream fStream = File.Create(path); //Add out custom surrogates to the Surrogate Surrogates.AddSurrogates(ref surrogate); //Add the surrogates to the BinaryFormatter binary.SurrogateSelector = surrogate; //Create a new instance of the DataValues script DataValues saver = new DataValues(); //Set all the values you want to save saver.Hours = dateLogic.Hours; saver.Minutes = dateLogic.Minutes; saver.Day = dateLogic.Day; saver.Month = dateLogic.Month; saver.Year = dateLogic.Year; saver.GameObjects = collectObjects.collect(); saver.Keywords = keywords.Keywords; //Serialize the saverinstance to the fstream binary.Serialize(fStream, saver); //Close the stream fStream.Close(); return("Successfully saved your data!"); }
/// <summary> /// Gets the index of the previous full character. /// </summary> public static int PrevCharIndex(this ITsString tss, int ich) { if (ich < 0 || ich >= tss.Length) { throw new ArgumentOutOfRangeException("ich"); } return(Surrogates.PrevChar(tss.Text, ich)); }
private bool IsValidInsertionPoint(int runIndex, int ichRun) { if (Surrogates.IsTrailSurrogate(Para.Source.ClientRuns[runIndex].Text[ichRun])) { return(false); } int prevLogicalChars = Para.Source.ClientRuns.Take(runIndex).Sum(run => run.Length); int ichRen = Para.Source.LogToRen(Para.Source.LogToRen(prevLogicalChars + ichRun)); for (var box = Para.FirstBox; box != null; box = box.Next) { var sbox = box as StringBox; if (sbox == null) { continue; } if (sbox.IchMin > ichRen) { return(true); // we've passed any box that might object } if (sbox.IchMin + sbox.RenderLength >= ichRen) { // This one will typically determine it. // Enhance JohnT: remove the VwGraphics argument from IsValidInsertionPoint; // no implementation uses it. As we switch to the new Graphite interface, we may // drop this altogether, and skip diacritics just based on unicode properties. var isValidInsertionPoint = sbox.Segment.IsValidInsertionPoint(sbox.IchMin, null, ichRen); if (isValidInsertionPoint == LgIpValidResult.kipvrBad) { return(false); // this box is sure it is no good. } if (isValidInsertionPoint == LgIpValidResult.kipvrOK) { return(true); // this box is sure it is fine } // otherwise possibly try one more: we may be at a boundary. } } return(true); // assume OK unless vetoed. }
/// <summary> /// Implement the backspace key function (delete one character, or merge two paragraphs). /// </summary> public void Backspace() { Invalidate(); // while we still know the old position. if (Hookup == null) { return; } if (StringPosition == 0) { if (Hookup.ClientRunIndex == 0) { BackspaceDeleteLineBreak(); return; } if (Para.Source.ClientRuns[Hookup.ClientRunIndex - 1] is TextClientRun) { // Delete at end of previous run. var prevClientRun = Para.Source.NonEmptyStringClientRunEndingBefore(Hookup.ClientRunIndex); if (prevClientRun == null) { return; } // Enhance JohnT: maybe some kind of hookup can merge with previous para or delete an embedded object? CopyFrom(prevClientRun.SelectAtEnd(Para)); Debug.Assert(StringPosition != 0, "should have selected at the END of a non-empty run"); } } string oldValue = Hookup.Text; int newPos = Surrogates.PrevChar(oldValue, StringPosition); // Enhance JohnT: should we delete back to a base? var start = new InsertionPoint(Hookup, newPos, false); if (!Hookup.CanDelete(start, this)) { return; } Hookup.Delete(start, this); StringPosition = newPos; }
public void TestStringCase() { CaseFunctions cf = new CaseFunctions("en"); Assert.AreEqual(StringCaseStatus.allLower, cf.StringCase("abc")); Assert.AreEqual(StringCaseStatus.allLower, cf.StringCase("")); Assert.AreEqual(StringCaseStatus.allLower, cf.StringCase(null)); Assert.AreEqual(StringCaseStatus.title, cf.StringCase("Abc")); Assert.AreEqual(StringCaseStatus.title, cf.StringCase("A")); Assert.AreEqual(StringCaseStatus.mixed, cf.StringCase("AbC")); Assert.AreEqual(StringCaseStatus.mixed, cf.StringCase("ABC")); Assert.AreEqual(StringCaseStatus.mixed, cf.StringCase("aBC")); int surrogateUc = 0x10400; // DESERET CAPITAL LETTER LONG I int surrogateLc = 0x10428; // DESERET SMALL LETTER LONG I string strUcSurrogate = Surrogates.StringFromCodePoint(surrogateUc); string strLcSurrogate = Surrogates.StringFromCodePoint(surrogateLc); // A single upper case surrogate is treated as title. Assert.AreEqual(StringCaseStatus.title, cf.StringCase(strUcSurrogate)); Assert.AreEqual(StringCaseStatus.title, cf.StringCase(strUcSurrogate + "bc")); Assert.AreEqual(StringCaseStatus.mixed, cf.StringCase(strUcSurrogate + "bC")); Assert.AreEqual(StringCaseStatus.allLower, cf.StringCase(strLcSurrogate + "bc")); }
public RangeSelection ExpandToWord() { var cpe = LgIcuCharPropEngineClass.Create(); RangeSelection rangeSel = new RangeSelection(this, new InsertionPoint(Hookup, StringPosition + 1, AssociatePrevious)); var backwardSel = new InsertionPoint(Hookup, StringPosition, AssociatePrevious); var forwardSel = new InsertionPoint(Hookup, StringPosition, AssociatePrevious); while (true) { if (backwardSel.StringPosition == 0) { break; } backwardSel.StringPosition--; char testChar = backwardSel.ContainingRun.Text[backwardSel.StringPosition]; int testInt = testChar; if (Surrogates.IsTrailSurrogate(testChar)) { backwardSel.StringPosition--; testInt = Surrogates.Int32FromSurrogates(backwardSel.ContainingRun.Text[backwardSel.StringPosition], testChar); } else if (Surrogates.IsLeadSurrogate(testChar)) { testInt = Surrogates.Int32FromSurrogates(testChar, backwardSel.ContainingRun.Text[backwardSel.StringPosition + 1]); } if (!cpe.get_IsNumber(testInt) && !cpe.get_IsWordForming(testInt) || backwardSel.ContainingRun.WritingSystemAt(backwardSel.StringPosition) != ContainingRun.WritingSystemAt(StringPosition)) { backwardSel.StringPosition++; break; } rangeSel = new RangeSelection(backwardSel, this); } backwardSel = rangeSel.Anchor; while (true) { if (forwardSel.StringPosition == forwardSel.ContainingRun.Length) { if (backwardSel.StringPosition == forwardSel.StringPosition) { return(null); } break; } char testChar = forwardSel.ContainingRun.Text[forwardSel.StringPosition]; int testInt = testChar; if (Surrogates.IsLeadSurrogate(testChar)) { forwardSel.StringPosition++; testInt = Surrogates.Int32FromSurrogates(testChar, forwardSel.ContainingRun.Text[forwardSel.StringPosition]); testChar = (char)testInt; } else if (Surrogates.IsTrailSurrogate(testChar)) { testInt = Surrogates.Int32FromSurrogates(forwardSel.ContainingRun.Text[forwardSel.StringPosition - 1], testChar); testChar = (char)testInt; } if (!cpe.get_IsNumber(testInt) && !cpe.get_IsWordForming(testInt) || forwardSel.ContainingRun.WritingSystemAt(forwardSel.StringPosition) != ContainingRun.WritingSystemAt(StringPosition)) { if (testChar.Equals(" ".ToCharArray()[0])) { forwardSel.StringPosition++; rangeSel = new RangeSelection(backwardSel, forwardSel); } break; } forwardSel.StringPosition++; rangeSel = new RangeSelection(backwardSel, forwardSel); } return(rangeSel); }
/// <summary> /// Shorten the current line. Currently this is only called when the last thing on the line /// is a string box. If possible, replace its segment with a shorter one. If this is not possible, /// and it is not the first thing on the line, remove it altogether. If it IS the first thing on /// the line, do nothing. We'll live with the bad break, because there is nothing better we know /// how to do. /// Returns true if successful, which means FinalizeLine should be called again. False if /// unsuccessful, to prevent infinite loop. /// </summary> private bool Backtrack() { var lastBox = m_lines.Last().LastBox as StringBox; while (lastBox != null) { // We want to call FindLineBreak again with the same arguments we used to create the segment // of lastBox, except that ichLimBacktrack should prevent including the last character. // (We expect that is is NOT a white-space-only segment, since we were not able to break after it.) int ichMin = lastBox.IchMin; int ichLim = ichMin + lastBox.Segment.get_Lim(ichMin); //int dxWidthLast = lastBox.Segment.get_Width(ichMin, m_layoutInfo.VwGraphics); int ichLimBacktrack = ichLim - 1; // skip back one if we're splitting a surrogate. if (ichLimBacktrack > 0) { string charsAtLim = Fetch(ichLimBacktrack - 1, ichLimBacktrack + 1); if (Surrogates.IsTrailSurrogate(charsAtLim[1]) && Surrogates.IsLeadSurrogate(charsAtLim[0])) { ichLimBacktrack--; } } int runIndex = m_renderRunIndex; // what would have beem m_renderRunIndex when making lastBox's segment. while (runIndex > 0 && ichMin < m_renderRuns[runIndex].RenderStart) { runIndex--; } var renderer = m_layoutInfo.GetRenderer(m_renderRuns[runIndex].Ws); int ichRunLim = GetLimitOfRunWithSameRenderer(renderer, runIndex); ILgSegment seg; int dichLim, dxWidth; LgEndSegmentType est; bool mustGetSomeSeg = m_currentLine.FirstBox == lastBox; var twsh = LgTrailingWsHandling.ktwshAll; bool runRtl = m_layoutInfo.RendererFactory.RightToLeft(m_renderRuns[runIndex].Ws); bool paraRtl = m_para.Style.RightToLeft; if (runRtl != paraRtl) { twsh = LgTrailingWsHandling.ktwshNoWs; } var spaceLeftOnCurrentLine = m_spaceLeftOnCurrentLine + lastBox.Width; renderer.FindBreakPoint(m_layoutInfo.VwGraphics, m_para.Source, null, ichMin, ichRunLim, ichLimBacktrack, false, mustGetSomeSeg, spaceLeftOnCurrentLine, LgLineBreak.klbWordBreak, mustGetSomeSeg ? LgLineBreak.klbClipBreak : LgLineBreak.klbWordBreak, twsh, false, out seg, out dichLim, out dxWidth, out est, null); if (seg == null) { // can't make any shorter segment here. // Can we backtrack further by getting rid of this box altogether? Box boxBefore = m_lines.Last().BoxBefore(lastBox); if (boxBefore is StringBox) { lastBox = (StringBox)boxBefore; continue; } // Currently backtracking should not need to remove a non-string box, because we always allow // breaking after them. So if boxBefore is not a string box, we can break after it. m_currentLine.RemoveFrom(lastBox); m_ichRendered = ichMin; m_spaceLeftOnCurrentLine = spaceLeftOnCurrentLine; m_renderRunIndex = AdvanceRenderRunIndexToIch(m_ichRendered, m_renderRunIndex); return(true); } m_currentLine.RemoveFrom(lastBox); AddBoxToLine(seg, ichMin, dichLim, est, spaceLeftOnCurrentLine); ILgSegment whiteSpaceSeg; if (twsh == LgTrailingWsHandling.ktwshNoWs) { // Add a white space segment if possible. renderer.FindBreakPoint(m_layoutInfo.VwGraphics, m_para.Source, null, m_ichRendered, ichRunLim, ichRunLim, false, true, m_spaceLeftOnCurrentLine, LgLineBreak.klbWordBreak, LgLineBreak.klbWordBreak, LgTrailingWsHandling.ktwshOnlyWs, false, out whiteSpaceSeg, out dichLim, out dxWidth, out est, null); if (seg != null) { AddBoxToLine(whiteSpaceSeg, m_ichRendered, dichLim, est, m_spaceLeftOnCurrentLine); } } m_renderRunIndex = AdvanceRenderRunIndexToIch(m_ichRendered, m_renderRunIndex); return(true); } return(false); // no better break available, use the line as it is. }